Handling response from an ASP.NET web service using Jquery's Ajax function
I have this response coming from a ASP.NET web service
- <string xmlns="http://Walkthrough/XmlWebServices/">
- {"approverName":"","emailAddress":"","companyName":"ABC","address":{"streetAddress1":"12 BlahBlah","streetAddress2":"","state":"ON","zipCode":"","country":"SO","phoneNumber":""},"tabledata:"[{"vendorPart":"AAAAA","partDescription":"N/A","price":"0.00","quantity":"28"},{"vendorPart":"BBBBBBB","partDescription":"N/A","price":"0.00","quantity":"3"},{"vendorPart":"CCCCCC","partDescription":"N/A","price":"0.00","quantity":"25"}]}
- </string>
which is being called with this jquery function:
- $(document).ready(function() {
- $.ajax({
- type: "POST",
- url: "http://www.webservice.com/blahblah.asmx/blahb123",
- data: "tnWsGuid=TEST1",
- dataType: "script",
- success: function(msg)
- {
- alert("sucess")
- },
- error: function(e)
- {
- alert(JSON.stringify(e));
- }
- });
- });
My first question is this, I was having 403 forbidden issues with this function but omitting the contentType changed that. Then I was getting XML parsing issue and on a whim changing the dataType to script fixed that and gave me a response and I hit the success function. Why did that work?
I also would like to know how I can print out this data, because trying to treat it as json won't work, neither does XML.
In chrome I receive this warning:
- Resource interpreted as Script but transferred with MIME type text/xml: "http://www.webservice.com/blahblah.asmx/blahb123?tnWsGuid=TEST1&_=1366025879568."
The part appended to the end of this url is confusing me (after TEST1).
In the console I also get this error in chrome:
- Uncaught SyntaxError: Unexpected token <
Firebug gives me:
- SyntaxError: syntax error
- [Break On This Error]
-
- <?xml version="1.0" encoding="utf-8"?>
- <string xmlns="http://Walkthrough/XmlWebServices/">
- {"approverName":"","emailAddress":"","companyName":"ABC","address":{"streetAddress1":"12 BlahBlah","streetAddress2":"","state":"ON","zipCode":"","country":"SO","phoneNumber":""},
- "tabledata:"[{"vendorPart":"AAAAA","partDescription":"N/A","price":"0.00","quantity":"28"},{"vendorPart":"BBBBBBB","partDescription":"N/A","price":"0.00","quantity":"3"},{"vendorPart":"CCCCCC","partDescription":"N/A","price":"0.00","quantity":"25"}]}
- </string>
So basically now that the dataType is script I get some sort of response but still have no idea how to parse this data. Preferably into a html table.
I hope you can help! Thanks for reading!
Here is a link to the header information logged by Firebug
here