Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何将ajax变量值传递到php页面?_Php_Ajax - Fatal编程技术网

如何将ajax变量值传递到php页面?

如何将ajax变量值传递到php页面?,php,ajax,Php,Ajax,我试图使用ajax传递一个变量值。当我运行显示正确值“hi”的文件警报框时,我在test.php上遇到了一个错误 注意:未定义的索引:第19行C:\wamp64\www\abrar\superadmin\test.php中的消息 我的代码是 superAdminView.php HTML var message=“Hi”; $.ajax({ url:“test.php”, 方法:“张贴”, 数据:{ “消息”:消息 }, 成功:功能(数据){ 警报(信息); }, 错误:函数(){ 警惕(“不

我试图使用ajax传递一个变量值。当我运行显示正确值“hi”的文件警报框时,我在test.php上遇到了一个错误

注意:未定义的索引:第19行C:\wamp64\www\abrar\superadmin\test.php中的消息

我的代码是

superAdminView.php

HTML


var message=“Hi”;
$.ajax({
url:“test.php”,
方法:“张贴”,
数据:{
“消息”:消息
},
成功:功能(数据){
警报(信息);
},
错误:函数(){
警惕(“不正常”);
}
});
test.php

PHP


但是它在
test.php中显示了一个错误


您必须纠正您的
成功:功能

success: function(data) {
  /* data is the return string form the PHP script! */
  alert("PHP response is: "+ data);
  /* message is the input you send to the PHP script! */
  // alert(message); -> this is incorrect
}

此更改后,请运行父脚本(
superadminviewbtn.php
)重试。它起作用了吗?

您必须纠正您的
成功:功能:

success: function(data) {
  /* data is the return string form the PHP script! */
  alert("PHP response is: "+ data);
  /* message is the input you send to the PHP script! */
  // alert(message); -> this is incorrect
}

此更改后,请运行父脚本(
superadminviewbtn.php
)重试。它起作用了吗?

您似乎正在直接在浏览器中打开
test.php
。您只能在
success
handler中看到来自AJAX POST请求的响应,请尝试使用“postman”确认您的PHP是否按预期工作。使用postman,您可以使用包含消息的JSON正文来创建POST请求。然后您可以分别关注JavaScript。
var\u dump
使用
$\u POST
变量,查看您获得的数据。此外,如果有什么东西阻止了POST请求,请检查web服务器/localhost设置。AJAX请求和通过浏览器地址栏直接加载test.php时发出的请求是两个独立的请求,它们彼此无关。您只将参数与AJAX请求一起发送,因此它仅在由该请求触发的脚本的运行实例中可用。如果您希望通过AJAX发送的数据在以后的其他页面或其他请求中可用,则必须将其存储到会话或其他内容中。您似乎正在浏览器中直接打开
test.php
。您只能在
success
handler中看到来自AJAX POST请求的响应,请尝试使用“postman”确认您的PHP是否按预期工作。使用postman,您可以使用包含消息的JSON正文来创建POST请求。然后您可以分别关注JavaScript。
var\u dump
使用
$\u POST
变量,查看您获得的数据。此外,如果有什么东西阻止了POST请求,请检查web服务器/localhost设置。AJAX请求和通过浏览器地址栏直接加载test.php时发出的请求是两个独立的请求,它们彼此无关。您只将参数与AJAX请求一起发送,因此它仅在由该请求触发的脚本的运行实例中可用。如果希望通过AJAX发送的数据在以后的其他页面或其他请求中可用,则必须将其存储到会话或其他内容中。
success: function(data) {
  /* data is the return string form the PHP script! */
  alert("PHP response is: "+ data);
  /* message is the input you send to the PHP script! */
  // alert(message); -> this is incorrect
}