我試圖使用ajax訪問其餘服務。
如果我會貼在任何網頁瀏覽器這個鏈接就會給這樣的結果:
{"SessionID":"a7f58a4a-f922-47c1-8351-d2035df4968c","SourceIP":"127.0.0.1","UserID":313}
(鏈接已更改爲安全)
https://thisisjustasample/Rest/Authenticate/Login?username=user&password=pass123&ip=127.0.0.1
但是我發現沒有運氣訪問鏈接用ajax:
從 '查看' 部分的呼叫:
getdata('https://thisisjustasample/Rest/Authenticate/Login?username=user&password=pass123&ip=127.0.0.1');
js文件中的函數:
function getdata(url) {
$.ajax({
url: url,
type: 'GET',
contentType: 'application/json',
success: function (data) {
if (data) {
showtooltip(data);
}
},
error: function (xhr, ajaxOptions, error) {
showtooltip(xhr.status + ': ' + error);
}
});
}
它總是返回'0'狀態。當我檢查我的數據庫時,數據沒有任何改變。代碼有什麼問題?
你在'firebug'中看到了什麼? – gdoron 2012-04-04 09:20:12
你確定你沒有進行跨域請求嗎? – 2012-04-04 09:20:53
我不熟悉螢火蟲,但我會嘗試使用它。 – fiberOptics 2012-04-04 09:21:23