我試圖調用webservice的asp.net javascript中/ jQuery的, 我已經試過這樣的例子很多,但遺憾的是沒有成功,如何在JavaScript或JQuery中調用SOAP(XML)webservice?
這裏是我目前正試圖代碼,
login("[email protected]", "123456");
var productServiceUrl = 'http://localhost:50575/Service1.asmx?op=test'; // Preferably write this out from server side
function login(Email, Password) {
var soapMessage = '<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> \
<soap:Body> \
<login xmlns="http://test.com/"> \
<Email>' + Email + '</Email> \
<Password>' + Password + '</Password> \
</login> \
</soap:Body> \
</soap:Envelope>';
$.ajax({
url: productServiceUrl,
type: "GET",
dataType: "xml",
data: soapMessage,
complete: endSaveProduct,
error: function (a, b, c) {
alert(a + "\n" + b + "\n" + c);
},
contentType: "text/xml; charset=\"utf-8\""
});
return false;
}
function endSaveProduct(xmlHttpRequest, status) {
$(xmlHttpRequest.responseXML)
.find('loginResult')
.each(function() {
alert($(this).find('Message').text());
});
}
請幫我, 在此先感謝。
所以,你有什麼解決辦法兄弟? – 2012-08-05 12:23:40
你是什麼意思?我剛剛說過,由於同源安全策略,這是不可能的。服務器必須允許使用我無法控制的標題。 – Esailija 2012-08-05 12:24:58
好吧,謝謝:) – 2012-08-05 12:30:47