multiple return values from PHP with jQuery AJAX

前端 未结 3 615
刺人心
刺人心 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:05

    Make your response return JSON, you'll need to change your jQuery to this, so the expected dataType is json:

    $.ajax
    ({
        type: "POST",
        url: "customerfilter.php",
        dataType: 'json',
        cache: false,
        success: function(data)
        {
            $(".custName").html(data.message1);
            $(".custName2").html(data.message2);
        }
    });
    

    Then you need to encode your response as a JSON Array:

      "Hi", 
          "message2" => "Something else")
     ) ?>
    

提交回复
热议问题