我知道有很多这样的问题,但我已经在他们和其他网站上浏览了4个小时,试图解决这个问题。我正在尝试让main.js通过ajax发布数据,然后php应该回显这些数据。如果它不工作,它将回显"null“。它一直在回显"null“而不是"John”。我知道jquery和main.js链接是有效的,我对它们进行了测试。下面是main.js:
$(document).ready(function(){
$.post("index.php", { test: "John"} );
});下面是index.php的php部分:
<?php
$var = "null";
if(isset($_POST['test'])) {
$var = $_POST['test'];
}
echo $var;
?>我希望你能解决我的问题,并提前感谢你。
发布于 2017-04-29 06:48:02
您缺少来自服务器的响应的回调函数。
$.post( "index.php",{ test: "John"}, function( data ) {
alert(data);
});或者你可以这样做:
$.post( "index.php",{ test: "John"})
.done(function( data ) {
alert( "Data Loaded: " + data );
});请查看文档Documentation
发布于 2017-04-29 06:53:16
试一试
jQuery
var available agent = 1;
jQuery.ajax({
type: "POST",
url: "your-url",
data: available_agent,
dataType: 'json',
cache: false,
contentType: false,
processData: false,
success: function(data){
owner = data['round_robin_agent'];
},
error : function () {
alert("error");
}
});PHP脚本
public function round_robin() {
//Do your work
$round_robin_agent = 'rob';
$results_array = array(
'round_robin_agent' => $round_robin_agent
);
return json_encode($results_array);
}发布于 2017-04-29 18:30:34
下载HTTP Trace chrome扩展,回溯ajax调用并分享屏幕截图。
https://chrome.google.com/webstore/detail/http-trace/idladlllljmbcnfninpljlkaoklggknp
https://stackoverflow.com/questions/43689830
复制相似问题