I'm trying to test out a new web service and it seems to be working fine except when I consume it using jQuery. jQuery.ajax first of all isn't sending an OPTIONS request, just a GET request, even though it is cross-domain, and then when the response comes back 200 OK with an XML response jQuery.ajax throws an error, responseText is empty and responseXML is undefined. Here's my code:
- var name = prompt("Please enter your name", "Harry Potter");
- var XmlUrl = "http://c12723/HostDevServer/HelloWorldService.svc/GetMessage?name=" + encodeURI(name);
- jQuery.ajax({dataType: "xml", error: function(x,y,z){
- alert(y + ": " + z + "\nCould not read XML");
- alert(x.responseXML);
- }, success: function(r_data, r_textStatus, r_jqXHR){
- jQuery('#message').text(r_data);
- }, url: XmlUrl});
And here is the response from the server:
HTTP/1.1 200 OK
Server: Microsoft-IIS/5.1
Date: Wed, 21 Nov 2012 21:07:54 GMT
X-Powered-By: ASP.NET
X-AspNet-Version: 4.0.30319
Content-Length: 136
Cache-Control: private
Content-Type: application/xml; charset=utf-8
<GetMessageResponse xmlns="http://tempuri.org/"><GetMessageResult>Hello world from Harry Potter!</GetMessageResult></GetMessageResponse>