我想從使用chrome的jquery(ajax)中打一個webservice。但是,當我嘗試調用Web服務我得到下面的錯誤,它甚至沒有到達服務器XMLHttpRequest無法加載http:// localhost:8089/jquery。訪問控制 - 允許來源不允許原產地
Error :XMLHttpRequest cannot load http://tomohamm-t420:8089/jquery. Origin null is not allowed by Access-Control-Allow-Origin.
下面是一個樣本AJAX調用我使用的: //構建W/S-請求的查詢字符串作爲對象..
var id = '123';
var query = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:sch="http://www.tibco.com/schemas/jQuerySample/jquery/Schema.xsd"';
query += '<soapenv:Header/';
query += '<soapenv:Body';
query += '<sch:EmpDetailsRequest';
query += '<sch:empID' + id + '</sch:empID';
query += '</sch:EmpDetailsRequest';
query += '</soapenv:Body';
query += '</soapenv:Envelope';
// set end point url..
var endpointUrl = 'http://tomohamm-t420:8089/jquery';
//ajax call to W/S..
$.ajax({
url : endpointUrl,
type : "POST",
beforeSend : function(xhr) {
xhr.setRequestHeader("SOAPAction", "/GetEmpByID");
},
data : query,
dataType : "xml",
contentType : "text/xml; charset=\"utf-8\"",
complete : function(xmldata,stat,response) {
console.log("W/S-Response: "+xmldata.responseText);
},
success : function(data) {
console.log('W/S Successful!');
},
error : function(textStatus, errorThrown) {
console.log('W/S Failed!');
console.log('Error Status :: ' +textStatus);
console.log('Error Message :: ' +errorThrown);
}
});
我找到了一種避免這個問題的方法。這是我使用下面的命令來打開Chrome: CD C:\ Program Files文件(x86)的\谷歌\鍍鉻\應用 的chrome.exe - 禁用網絡安全
但這不能在每完成試圖打開我的應用程序的機器。 那麼無論如何,包括jquery應用程序內的這個設置,以便我可以直接打開chrome並運行它?
您能否讓我知道我需要爲適當的Access-Control-Allow-Origin標題添加哪些設置。 – user2773804