Reputation: 199
I have a html page with the following ajax method:
$(document).ready(function() {
$.ajax({
type: "POST",
url: "http://www.webservice.com/blahblah.asmx/blahb123",
data: "tnWsGuid=TEST1",
dataType: "json",
contentType: "application/json; charset=utf-8",
success: function(msg)
{
alert("sucess")
},
error: function(e)
{
alert(JSON.stringify(e));
}
});
});
Which is returning to me 403 forbidden. A fellow co-worker built the web service and I do not have access to the code nor do I have the current ability to change it as he is on vacation. I need to display this data - at this point everything I try is failing and giving me a 403 forbidden error. I have changed the url name and the success function to just a alert dialog for the purpose of displaying the code.
One other thing is that the json is wrapped in XML it seems, coming from a ASP.NET webservice which looks like this:
<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>
This was not the intention originally as I had expected to receive json however I can't do anything about it now and must deal with it in XML and just try and turn the json formatted inside into a json object.
I have tried as the following too:
$(document).ready(function() {
$.ajax({
type: "GET",
url: "http://www.webservice.com/blahblah.asmx/blahb123",
data: "tnWsGuid=TEST1",
dataType: "xml",
contentType: "text/xml",
success: function(msg)
{
alert("sucess")
},
error: function(e)
{
alert(JSON.stringify(e));
}
});
});
Finally I will output the Firebug response from FireFox here for both examples I've tried (json/xml)
Json: https://i.sstatic.net/oZHUg.jpg
XML: http://i.imgur.com/6qiGVwQ.jpg
Thank you very much for reading!
Upvotes: 0
Views: 8161
Reputation: 199
Well removing the contentType header seem's to remove the 403 forbidden.
Upvotes: 1
Reputation: 532
If the call is cross domain you may encounter issues if you don't use the dataType jsonp.
Upvotes: 1