我想讓jsonp調用與jquery和我的asp.net-mvc網站一起工作。 I found this article which i tried to copy,但我沒有在我的回調得到一個斷點:Jsonp結果不能在我的asp.net-mvc網站上工作
這裏是我的jQuery代碼:
$.ajax({
url: "http://www.mySite.com/MyController/Terms",
type: "GET",
dataType: "jsonp",
timeout: 10000,
jsonpCallback: "localJsonpCallback"
});
function localJsonpCallback(json) {
var terms = json.HTMLText;
$("#term2").html(terms);
}
這裏是我的控制器代碼:
public JsonpResult Terms()
{
var data = GetData();
return this.Jsonp(data);
}
其中JsonpResult和這.Jsonpare defined as per this page:
所以我可以「T似乎得到一個回調,但是當我打開Firebug的腳本部分,我看到列出的文件是在有關的URL,並具有:
Terms?callback=localJsonpCallback
,當我考慮的內容我看到正確的JSON對象內容:
localJsonpCallback({"HTMLText":"PRIVACY POLICY: Your privacy is very important to us"});
所以這告訴我數據回到客戶端,但回調似乎並沒有被解僱,文本輸入沒有被填充。
任何人都可以找到一個問題,我在做什麼或有任何解釋爲什麼這不會工作?
嘗試使用'url:「http://mySite.com/MyController/Terms」' – Rafay