我試圖連接到這個網絡服務:
但它提醒 「錯誤」 來
這是我用的腳本:
var varType;
var varUrl;
var varData;
var varContentType;
var varDataType;
var varProcessData;
function SetValue() {
varType = "POST";
varUrl = "http://www.w3schools.com/webservices/tempconvert.asmx/FahrenheitToCelsius";
varData = '{"Fahrenheit":"230"}';
varContentType = "application/json; charset=utf-8";
varDataType = "json";
varProcessData = true;
CallService();
}
function CallService() {
$.ajax({
type: varType,
url: varUrl,
data: varData,
contentType: varContentType,
dataType: varDataType,
processdata: varProcessData,
success: function (msg) {
ServiceSucceeded(msg);
},
error:function (xhr, ajaxOptions, thrownError){
alert(xhr.statusText);
alert(thrownError);
}
});
}
function ServiceSucceeded(result) {
alert("ServiceSucceeded");
varType = null; varUrl = null; varData = null; varContentType = null; varDataType = null; varProcessData = null;
}
我該怎麼辦?
你應該閱讀有關[同源策略(http://en.wikipedia.org/wiki/Same_origin_policy) – 2012-01-01 21:44:08
通過跨域請求時使用
dataType: 'jsonp'
方式,你不需要把所有的東西都設置爲'null' ......垃圾回收器負責處理這個問題。 – Ryan 2012-01-01 21:44:32你看起來究竟是什麼你回來與螢火蟲/ webinspector?你是否試圖用預設變量從控制檯手動執行此操作? – alonisser 2012-01-01 21:46:41