Php 使用jquery打印响应json

Php 使用jquery打印响应json,php,jquery,json,ajax,Php,Jquery,Json,Ajax,当我想通过消息警报打印响应json时,我遇到了一个问题。 这是我的剧本: $.ajax({ headers: { "Accept" : "application/json", "Content-Type": "application/json" }, url: "http://192.168.1.1:8000", type: "POST", data: JSON.stringi

当我想通过消息警报打印响应json时,我遇到了一个问题。 这是我的剧本:

$.ajax({
    headers: {          
        "Accept" : "application/json",         
        "Content-Type": "application/json"   
      },
    url: "http://192.168.1.1:8000",
    type: "POST",
    data: JSON.stringify(jsonString),
    error: function (xhr, ajaxOptions, thrownError) {
      $('#response').html(xhr); 
  },
  cache: false,
  success: function(xhr){
    alert(console.log(xhr));
 }
}))

这是我可以传递的信息。 “未定义”

此响应来自控制台 你可以这样做

alert(xhr);

完整代码如下所示

$.ajax({
        headers: {          
            "Accept" : "application/json",         
            "Content-Type": "application/json"   
          },
        url: "http://192.168.1.1:8000",
        type: "POST",
        dataType: "json",
        data: JSON.stringify(jsonString),
        error: function (xhr, ajaxOptions, thrownError) {
          $('#response').html(xhr); 
      },
      cache: false,
      success: function(xhr){
        alert(JSON.stringify(xhr));
     }

    });
console.log()没有返回值…请使用
console.log(xhr)
alert(xhr)
console.log()
不返回任何内容(意味着它返回
未定义的
),并且您正在尝试警告
consolelog
成功:函数(xhr){console.log(xhr);alert返回的值(JSON.stringify(xhr));}
您应该提到ajax中的数据类型:“JSON”
$.ajax({
        headers: {          
            "Accept" : "application/json",         
            "Content-Type": "application/json"   
          },
        url: "http://192.168.1.1:8000",
        type: "POST",
        dataType: "json",
        data: JSON.stringify(jsonString),
        error: function (xhr, ajaxOptions, thrownError) {
          $('#response').html(xhr); 
      },
      cache: false,
      success: function(xhr){
        alert(JSON.stringify(xhr));
     }

    });