0

我在 json 中得到响应(可以在 firebug 中检查),但这不会解析 json 响应并且没有显示结果。我做错了什么?我在文档http://docs.jquery.com/Plugins/Autocomplete上找不到任何东西

这是我的 JSON 响应

({"Contacts":[{"Phone":"","Email":"","Labels":"","Mobile":"12345678","Firstname":"john"}]});

这是我的 jQuery:

$("#destinations").autocomplete({
    source: function (request, response) {
        $.getJSON("http://localhost/contactApi.do?callback=?", 
          { 'contactMobile': request.term, maxRows: 12, style: "full" }, 
          function(data) {
              if(data.Contacts){
                  var x = $.map(data.Contacts, function(v, i){
                      console.log(v)
                      return {
                          label: v.Mobile + ' - ' + v.Firstname, 
                          v: v.Firstname
                      }
                  });
                  response(x);
              }
          }
        );        
    }
})
4

1 回答 1

0

有一次,问题出在服务器端,这发生在我身上。我将响应作为原始字符串而不是 JSON 发送。如果您能够看到从服务器发回的正确标头(内容类型:应用程序/json),请查看 firebug。此外,您应该能够使用 firebug 看到名为 JSON 的选项卡。添加正确的标头后,我能够使用 jQuery 反序列化这些值。

于 2013-02-06T00:39:16.370 回答