从PHP多个返回值与jQuery AJAX多个、返回值、PHP、jQuery

由网友(能奏大功)分享简介:我使用这个jQuery的code:I'm using this jQuery code:$.ajax({type: "POST",url: "customerfilter.php",data: dataString,cache: false,success: function(html){$(".custName...

我使用这个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);
});
阅读全文

相关推荐

最新文章