'JQuery AJAX call to SOAP Web Service - Access denied. Working in SOAP UI
JQuery AJAX call to SOAP Web Service throws exception as "Access denied". See screenshot. It is Working in SOAP UI so SOAP request seems correct. Please help in finding problem and fixing.
My other code screenshot - http://tinypic.com/r/2liasgl/5
<!DOCTYPE html>
<html>
<head>
<title>Calling Web Service from jQuery</title>
<script type="text/javascript" src="jquery-1.9.1.js"></script>
<script type="text/javascript">
$(document).ready(function () {
jQuery.support.cors = true;
$("#btnCallWebService").click(function (event) {
var wsUrl = "https://webservices..myservice.../";
var soapRequest = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:dictionary:com.myservice.webservices"><soapenv:Header xmlns:wsse="http://myservice.org/wss/2004/01/myservice-1.0.xsd"><wsse:Security soapenv:mustUnderstand="1"><wsse:UsernameToken><wsse:Username>efhueeudedujed</wsse:Username><wsse:Password Type="http://myservice-wss-username-token-profile-1.0#PasswordText">dfdjfhdkjfa</wsse:Password></wsse:UsernameToken></wsse:Security></soapenv:Header><soapenv:Body><urn:getETNInstances/></soapenv:Body></soapenv:Envelope>';
$.ajax({
type: "POST",
url: wsUrl,
contentType: "text/xml",
dataType: "xml",
data: soapRequest,
success: processSuccess,
error: processError
});
});
});
function processSuccess(data, status, req) {
if (status == "success")
$("#response").text($(req.responseXML).find("HelloResult").text());
}
function processError(data, status, req) {
alert(req.responseText + " " + status);
}
</script>
</head>
<body>
<h3>
Calling Web Services with jQuery/AJAX
</h3>
Enter your name:
<input id="txtName" type="text" />
<input id="btnCallWebService" value="Call web service" type="button" />
<div id="response" />
</body>
</html>
Solution 1:[1]
Possible problems are:
You're using absolute urls (with
https://serverdomain
). Some browsers block absolute urls even if they're not cross-domain request. Try using relative urls instead (withouthttps://serverdomain
) if you're not making cross-domain requests.If the above does not work, the other possible problem is you're performing a cross-domain request. If you need to perform cross-domain requests, you need to use some techniques like JSONP, CORS.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Khanh TO |