我有一個HttpListenerContext類,總是聽端口13001.曾經Ajax調用來我傳遞數據如下JQuery的阿賈克斯獲得迴應,但總是調用錯誤功能JSONP
context.Response.Close(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject("jsonp({'Status':'Good'})")), false);
接下來我調用時該服務器通過使用jQuery阿賈克斯如下
$.ajax({
url: "http://localhost:<13001>/hit/number',
type: "GET",
async: false,
contentType: "application/json",
dataType: "jsonp",
jsonp: "jsonp",
success: function (data, textStatus, xhr) {
console.log(data);
},
error: function (xhr, ajaxOptions, thrownError) {
console.log("Error");
}
});
阿賈克斯Get請求獲得成功,我能看到在Chrome網絡 - 響應>響應標籤如下
"jsonp({"Status":"Good"})"
但我無法在Ajax Success功能中獲得此消息。它總是顯示錯誤。任何人都可以告訴我我犯了什麼錯誤。
Response Headers
Access-Control-Allow-Origin:*
Cache-Control:private
Content-Length:23
Content-Type:application/javascript
Date:Fri, 27 Sep 2013 01:12:25 GMT
Server:Microsoft-HTTPAPI/2.0