$.ajax issue
$.ajax issue
Hi all
I have a problem with the $.ajax function. I have searched all over but nothing seems to work.
The problem is when i call a webservice I always get an error returned. Maybe my Soap request format is incorrect ? Can you help. Here is all my code ....
Thanks alot for any help, its been driving me mad !
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="Content/jquery.mobile-1.2.0.min.css" />
<script src="Scripts/jquery-1.6.4.min.js"></script>
<script src="Scripts/jquery.mobile-1.2.0.min.js"></script>
<link href="Content/StyleOverRide.css" rel="stylesheet" type="text/css" />
<script src="Scripts/MobileCRMCode.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function () {
$("#btnCallWebService").click(function (event) {
var wsUrl = "http://www.webservicex.net/stockquote.asmx";
var soapData = "";
soapData += "<?xml version=\"1.0\" encoding=\"utf-8\"?>";
soapData += "<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/\">";
soapData += "<soap:Body>";
soapData += "<web:GetQuote>";
soapData += "<web:symbol>AA</web:symbol>";
soapData += "</web:GetQuote>";
soapData += "</soap:Body>";
soapData += "</soap:Envelope>";
var soapRequest = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="http://www.webserviceX.NET/">\
<soapenv:Header/>\
<soapenv:Body>\
<web:GetQuote>\
<!--Optional:-->\
<web:symbol>AA</web:symbol>\
</web:GetQuote>\
</soapenv:Body>\
</soapenv:Envelope>';
$.ajax({
type: 'POST',
url: wsUrl,
cache: false,
success: function (data) {
var xml = data.xml;
alert("Working");
},
error: function (data) {
var xml = data.xml;
alert("error"); //[do something with the xml]
},
contentType: "text/xml",
data: soapData
});
});
});
</script>
</head>
<body>
<input id="txtName" type="text" />
<input id="btnCallWebService" value="Call web service" type="button" />
<div id="response" />
</body>
</html>