我寫在我的網站下面的web服務ASMX文件:問題與jQuery Tokeninput和asp.net web服務
[WebService(Namespace = "http://eumcore.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ScriptService]
public class jsonTest : System.Web.Services.WebService {
public jsonTest() {
}
[WebMethod(Description = "Gets the names matching part of a title.")]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public void getName() {
List<nameEntry> nameList = new List<nameEntry>();
nameList.Add(new nameEntry() {id="1", name="John"});
nameList.Add(new nameEntry() { id = "3", name = "Alex" });
this.Context.Response.ContentType = "application/json; charset=utf-8";
JavaScriptSerializer js = new JavaScriptSerializer();
string strJSON = js.Serialize(nameList);
this.Context.Response.Write(strJSON);
}
}
作爲一個開始,我想它每次都返回相同的陣列,webservice時的結果我把它直接是:
[{"id":"1","name":"John"},{"id":"3","name":"Alex"}]
哪一個是正確的應答,當我使用它作爲一個本地輸入的結果是好的,但是當我調用web服務中tokeninput的輸入方法(I分配一個錯誤消息發送到函數)我得到以下錯誤:「200 parsererror undefined」
任何人都可以幫我弄明白嗎?
感謝
多倫
編輯:用jQuery代碼玩弄後一點我設法接收數據,但我得到了以下錯誤:
parsererror
[{「id」:「1」,「name」:「aaA」},{「id」:「3」,「name」:「aaA」}] {「d」:null}
我不明白的是d是什麼,爲什麼它是空的?
當我在tokeninput的輸入法中調用webservice時,有什麼意思? –
從運行jQuery的html: –
您嘗試調用此webservice的Web頁面是否也託管在localhost:61965上,還是位於單獨的應用程序中? –