multiple return values from PHP with jQuery AJAX

前端 未结 3 609
刺人心
刺人心 2020-12-23 02:34

I\'m using this jQuery code:

$.ajax
({
    type: \"POST\",
    url: \"customerfilter.php\",
    data: dataString,
    cache: false,
    success: function(htm         


        
3条回答
  •  一整个雨季
    2020-12-23 03:01

    Use json_encode() to convert an associative array from PHP into JSON and use $.getJSON(), which will return a Javascript array.

    Example:

     "valueA", "b" => "valueB")); ?>
    

    In Javascript:

    $.getJSON("myscript.php", function(data) {
      alert("Value for 'a': " + data.a + "\nValue for 'b': " + data.b);
    });
    

提交回复
热议问题