php json_encode not returning proper json encoded string

前端 未结 2 1456
耶瑟儿~
耶瑟儿~ 2021-01-20 12:54

I am using a jquery ajax call which accepts json response :

 var posturl = \'/admin/getparamdetails/\';
    var data = \"adnetworkId=\"+adnetworkId;
    $.a         


        
相关标签:
2条回答
  • 2021-01-20 13:33

    you have to send the data as Content-Type "application/json", otherwise it won't work.

    Just add the following in your PHP File:

    header('Content-type: application/json');
    
    0 讨论(0)
  • 2021-01-20 13:49

    Use parseJSON on the return data:

    if (msg) {
      msg = $.parseJSON(msg);
      alert(msg.hello);
    }
    
    0 讨论(0)
提交回复
热议问题