如何从PHP中的JavaScript读取发布网址请求

我有在html中输入的表单。
然后,我添加了此javascript(jquery)笔画,以读取和收集表单中的所有值或数据。

var formData = $("#form").serialize();

当我

console.log(formData);

输出将显示:

calc-ownership = ooo&calc-activity = restaurant&calc-tax = usn&calc-tax-2 = charge&calc-bank = partners&calc-who-payments = client&operations_count = 0&calc-nomenclature = slim&documents_count = 0 = 0&calc-who-docs = client&staff_count = 0&calc-more%5B% 5D =专利&calc-more%5B%5D = alcohol&period =&price =&price_sber =&rate-name =&email-to =

然后我在jquery中找到了称为post $.post(path, formData, success, "json"); Request的函数, 如下所示: do.php?bank = partners

如您所见,它向我发出了邮政请求do.php
现在如何读取此查询并使用此数据?

$.post在jquery中找到了与之类似的东西。它是$.ajax 完整代码:

$.ajax({ url: path, method: "POST", data: {formData: formData} });

它运作良好。
但是我想和$.post

我目前正在查看自己的网址。它看起来:https://stackoverflow.com?ask=32321

我需要类似的东西才能用php从javascript读取此URL


波斯汪
浏览 122回答 3
3回答

叮当猫咪

好的,我会举例说明,如果您想使用url参数值,<script>let my_variable='<?php echo $_GET['url_param_name'];?>';</script>以上以获得更多帮助和理解。现在,您想将表单数据发送到php进行处理,因为我得到了您的答案。这是样本表格。<form id="my_form" name"my_form" method="POST" onsubmit="return send();">&nbsp; First name:<br>&nbsp; <input type="text" name="first_name" value="Mickey">&nbsp; <br>&nbsp; Last name:<br>&nbsp; <input type="text" name="last_name" value="Mouse">&nbsp; <br><br>&nbsp; <input type="submit" value="Submit"></form>&nbsp;要发布上述表格,我将使用javascript函数,<script>function send() {&nbsp; &nbsp; $.ajax&nbsp; &nbsp; ({&nbsp; &nbsp; &nbsp; &nbsp; type: 'POST',&nbsp; &nbsp; &nbsp; &nbsp; url: './path/your_php_file_where_form_data_processed.php',&nbsp; &nbsp; &nbsp; &nbsp; data:$('#my_form').serialize(),&nbsp; &nbsp; &nbsp; &nbsp; success: function () {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// do what you need to do on succeess&nbsp; &nbsp; &nbsp; &nbsp; },&nbsp; &nbsp; &nbsp; &nbsp; error: function (x, e) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // for error handling&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (x.status == 0) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; console.log('You are offline!! -&nbsp; Please Check Your Network.');&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } else if (x.status == 404) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; console.log('Requested URL not found.');&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } else if (x.status == 500) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; console.log('Internal Server Error.');&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } else if (e == 'parsererror') {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; console.log('Error. - Parsing JSON Request failed.');&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } else if (e == 'timeout') {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; console.log('Request Time out.');&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } else {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; console.log('Unknown Error. - ' + x.responseText);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; });&nbsp; &nbsp; return false;}</<script>现在,您需要仔细检查表单元素名称。在php文件中。让我们看看。<?php//include_once './../../classes/Database.php'; import if you have database configurations//session_start(); make sure to use sessions if your site using sessionsif(isset($_POST)){&nbsp; &nbsp; var_dump($_POST); //this will echo your form inputed data.&nbsp; &nbsp; //if you want use one by one posted data&nbsp; &nbsp; echo $_POST['first_name'];&nbsp; &nbsp; echo $_POST['last_name'];}else{&nbsp; &nbsp; echo 'Data not comes here';}?>认为这可能对您的任务有所帮助。

ITMISS

我可能误解了您的问题,但是在php中,您可以使用$ _POST ['variable_name']从发布中获取值。<?php &nbsp;&nbsp;$documents_count&nbsp;=&nbsp;$_POST['documents_count'] &nbsp;&nbsp;?>实际上,这在您的url中不是查询,而是变量。很抱歉,如果不是您要的。
打开App,查看更多内容
随时随地看视频慕课网APP