2011-08-25 63 views
0

我必須在這裏丟失的東西,但我試圖使用jQuery UI的自動完成與ASP.NET頁面的方法。我使用JSON.NET序列化的方法,這絕對作品的響應,並返回此:jQuery與JSON.NET的自動完成JSON

[{"ADMIN_ID":1,"ADMIN_NAME":"SMITH"}] 

...這裏是我的jQuery代碼:

$("#txtName").autocomplete({ 
    source: function (request, response) { 
     $.ajax({ 
      type: "POST", 
      url: "MyPage.aspx/GetPerson", 
      data: "{ 'q': '" + request.term + "', 'limit': '10' }", 
      contentType: "application/json", 
      dataFilter: function (data) { return data; }, 
      success: function (data) { 
       var result = $.parseJSON(data.d) 
       response($.map(result, function (item) { 
        return { 
         label: item.ADMIN_NAME, 
         value: item.ADMIN_ID 
        } 
       })) 
      }, 
      error: function (xhr, status, errorThrown) { 
       alert("Error: " + xhr.responseText); 
      } 
     }); 
    }, 
    minLength: 1 
}); 

問題是,自動完成從不顯示任何項目。有任何想法嗎?

+0

我是個白癡,我沒有解析JSON,當它來到從我的頁面的方法了。添加了以上代碼:var result = $ .parseJSON(data.d) –

回答

0

先試試這個,我覺得你的反應(......)代碼的元兇:

$('#txtName').result(function(event, data, formatted) { 
    $("#result").html(!data ? "No match!" : "Selected: " + formatted); 
}); 
+0

對不起,#result僅用於顯示方法中的JSON字符串。我把它從原始代碼中拿出來了。 –