我正在尝试学习Jquery AJAX函数,但是我很难弄清楚如何将PHP变量传递到我的主文档。
这是我目前的代码:
<script>
var refreshId = setInterval(function() {
$.ajax({
url: "test.php",
dataType: "json", //the return type data is jsonn
success: function(data){ // <--- (data) is in json format
$('#testdiv').html(data.test1);
$('#testdiv').append(html(data.test2));
//parse the json data
}
});
}, 1000);
</script>
getJSON
。并使用 PHP 方法 json_encode 对数据进行编码并将其发送回您。 - JohnPjson_encode
,在JS端使用json调用。 - JohnPhtml(data.test2)
,请尝试使用$('#testdiv').html($('#testdiv').html() + data.test2);
。 - S L