前端代碼
$.ajax({ type: "POST", url: "http://localhost:9767/WebService1.asmx/HelloWorld?jsoncallback=?", data: "{}", dataType: "jsonp", success: function (data) { alert(data.result); } });webservice 的代碼
public void HelloWorld() { string callbackMethodName = HttpContext.Current.Request.Params["jsoncallback"] ?? ""; HttpContext.Current.Response.Write(callbackMethodName + "({result:'Hello World'})"); HttpContext.Current.Response.End(); }這樣會(huì)得到

但是如果用這樣的代碼
如果url不加?jsoncallback=?
$(function () { $.ajax({ type: "POST", url: "http://localhost:9767/WebService1.asmx/HelloWorld", data: "{}", dataType: "jsonp", success: function (data) { alert(data.result); } });
public string HelloWorld() { return "Hello World"; }
則會(huì)返回一個(gè)xml (
<?xml version="1.0" encoding="utf-8"?><string xmlns="http://tempuri.org/">Hello World</string>
) 并且會(huì)不去回調(diào)函數(shù) 這是怎么回事,筆者對(duì)webservice 不是很了解 也是剛剛接觸 有知道的能告訴下筆者 筆者會(huì)萬(wàn)分感謝
新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注