从PHP多个返回值与jQuery AJAX [英] multiple return values from PHP with jQuery AJAX
本文介绍了从PHP多个返回值与jQuery AJAX的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用这个jQuery的code:
I'm using this jQuery code:
$.ajax
({
type: "POST",
url: "customerfilter.php",
data: dataString,
cache: false,
success: function(html)
{
$(".custName").html(html);
}
});
我怎么可以做这样的事情: $(。projDesc)HTML(HTML1);
因此,我可以返回的结果分成两个HTML元素?
How can i do something like this: $(".projDesc").html(html1);
So i can split the returned results into two html elements?
echo "<p>" .$row['cust_name']. "</p>";
这就是我使用的是PHP,我想呼应,我可以投入另一个HTML元素另一份声明
thats the PHP i'm using and i want to echo another statement which i can put into another HTML element
这是否有道理?
推荐答案
使用 json_en code()
来转换PHP关联数组到JSON,并使用 $。的getJSON()
,它会返回一个JavaScript数组。
Use json_encode()
to convert an associative array from PHP into JSON and use $.getJSON()
, which will return a Javascript array.
例如:
<?php echo json_encode(array("a" => "valueA", "b" => "valueB")); ?>
在JavaScript的:
In Javascript:
$.getJSON("myscript.php", function(data) {
alert("Value for 'a': " + data.a + "\nValue for 'b': " + data.b);
});
这篇关于从PHP多个返回值与jQuery AJAX的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文