0

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!

Edit:

Here is a link to the header information logged by Firebug here

2 Answers 2

1

your need to set datatype to json as the server send a json array. see the datatype section here http://api.jquery.com/jQuery.ajax/

Sign up to request clarification or add additional context in comments.

1 Comment

When I change it to json I get the error from the code (status: 0, readyState: 0, StatusText: error) and this error (in chrome) XMLHttpRequest cannot load http://www.webservice.com/blahblah.asmx/blahb123s. Origin null is not allowed by Access-Control-Allow-Origin.
0

I have fixed this issue and successfully have it working on IE returning the dataset (not yet working on Chrome and Firefox due to the asynchronous problem with the two which I hope will be fixed when hosting this page. I added $.support.cors = true; right before the ajax function and my new success function properly show's the data like so:

function(data, status, jqxhr) { xmlString = data;
alert(xmlString); }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.