Javascript 通过jqueryajax的SOAP请求
我有一个运行服务的服务器,我想每隔一段时间运行一个对服务的ping请求,这样我就可以知道它什么时候准备好了 已获取以下Javascript 通过jqueryajax的SOAP请求,javascript,jquery,ajax,web-services,soap,Javascript,Jquery,Ajax,Web Services,Soap,我有一个运行服务的服务器,我想每隔一段时间运行一个对服务的ping请求,这样我就可以知道它什么时候准备好了 已获取以下ping.dat文件: <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:dvt="[private]"> <soapenv:Header /> &l
ping.dat
文件:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:dvt="[private]">
<soapenv:Header />
<soapenv:Body>
<dvt:Ping/>
</soapenv:Body>
</soapenv:Envelope>
当我使用SoapUI调用服务并加载ping请求时,它工作正常
当我使用JS函数时,浏览器会报告:
选项[private]200(OK)jquery-1.10.2.js:8706
XMLHttpRequest无法加载[private]。请求的资源上不存在“Access Control Allow Origin”标头。起源'http://localhost:8080因此,不允许访问
原因是什么?消息很清楚:请求的资源上不存在“Access Control Allow Origin”头 如果您确实在执行跨域Ajax请求,那么服务器必须使用适当的HTTP头进行响应。浏览器发出一个选项HTTP请求,并通过查看收到的头来检查服务器是否“批准”访问。如果缺少标题,则浏览器有义务返回错误并禁止对资源的请求 有关详细信息,请参见此处: SoapUI不像浏览器那样受影响,所以从SoapUI ping web服务是有效的
function doAjax() {
//load request document
$.ajax({
cache: false,
crossDomain: true,
async: true,
dataType: 'xml',
type: 'POST',
data: null,
url: "./ping.dat",
error: function(xhr, sta, err){ alert(err); },
success: function(ret, sta, xhr){
//ping service
$.ajax({
cache: false,
crossDomain: true,
async: false,
processData: false,
contentType: "text/xml; charset=\"UTF-8\"",
dataType: 'xml',
data: processXML(xhr.responseText),
type: 'POST',
url: "[private]",
error: function(xhr, sta, err){
alert(err);
},
success: function(ret, sta, xhr){
$('#response').text($.trim(ret));
},
complete: function(xhr, sta){
alert('complete');
},
});
}
});
}
function processXML(text){
var ret = null;
if ((typeof(ret) !== 'undefined')&&(text !== null)&&(text.length !== 0))
ret = $.trim(text.replace(/[\n\t]+/g, ''));
return ret;
}