如何从PHP数据返回到一个jQuery AJAX调用 [英] How to return data from PHP to a jQuery ajax call
本文介绍了如何从PHP数据返回到一个jQuery AJAX调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我用ajax发布的一些数据。我想操纵该数据并返回到给主叫jQuery脚本。
I am posting some data using ajax. I want to manipulate that data and return to to the calling jQuery script.
下面是我的jQuery的:
Here is my jQuery:
$.ajax({
type: "POST",
url: "somescript.php",
datatype: "html",
data: dataString,
success: function() {
//do something;
}
});
下面是我somescript.php服务器上:
Here is my somescript.php on the server:
<?php
//manipulate data
$output = some_function(); //function outputs a comma-separated string
return $output;
?>
我这样做正确地在服务器端,以及如何访问返回的字符串Ajax调用完成时?
Am I doing this correctly on the server side, and how do I access the return string when the ajax call completes?
推荐答案
我想它了。需要使用回声返回PHP替代。
I figured it out. Need to use echo in PHP instead of return.
<?php
$output = some_function();
echo $output;
?>
而JQ:
success: function(data) {
doSomething(data);
}
这篇关于如何从PHP数据返回到一个jQuery AJAX调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文