0

I'm using jquery to get a response from a webservice. The code is the same as I have seen used by many others without problems. I'm using a free webservice from http://www.service-repository.com/ just for testing.

My code looks like this:

jQuery.support.cors = true;

        $.ajax({
            type: "POST",
            url: "http://www.webservicex.com/globalweather.asmx/GetWeather",
            data: "{CityName: Boston}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            error: writeError(){...};
            success: beHappy(){...} });

As the title say, I get an internal server error.

the first line enables cross domain scripting. This is needed since the web service is remote. (without this line I get "No Transport" error)

pnuts
  • 58,317
  • 11
  • 87
  • 139
Amir
  • 1
  • 1
  • 1

1 Answers1

0

When I look at the url http://www.webservicex.com/globalweather.asmx/GetWeather?CityName=Boston I get the internal server error with a message saying that the CountryName is missing. does this call require CountryName?

I got this link by changing you query to:

$.ajax({
   type: "GET",
   url: "http://www.webservicex.com/globalweather.asmx/GetWeather",
   data: {'CityName': 'Boston'},
   contentType: "application/json; charset=utf-8",
   dataType: "json",
   success: function(data) {
   alert('done');
   }
});

and viewing the GET in firebug. When I looked at the service on www.webservicex.com all i could get was "Data Not Found". Are you sure this service returns JSON as all I can get is XML when i tried:

$.getJSON('http://www.webservicex.com/globalweather.asmx/GetWeather?callback=?',
{
    'CityName': 'Dublin', 
    'CountryName': 'Ireland'
},
function(data) {
     alert(data);
});

If you cant get the XML back via the ajax call.

An alternative approach would be to consume the webservice on the server side and then using an ajax call to your server to get the html to add to the page.

Dave
  • 3,812
  • 5
  • 31
  • 39
  • It does require a country name, but adding a county name leaves me with the same error.Besides, when trying a different service that takes no parameters I still get internal error. btw How did you find the exact error message? – Amir Aug 02 '11 at 13:49
  • And about the return type, I'm not sure it's json but if it isn't I'm expecting a lot of garbage returning and not a server error. – Amir Aug 02 '11 at 13:51
  • Hi Amir used the GET above in firebugs console and then looked at the request being made that allowed me to see the URL being generate. which was http://www.webservicex.com/globalweather.asmx/GetWeather?CityName=Boston Then i simply used that in the browser and could see the error message. – Dave Aug 02 '11 at 14:05
  • Thanks Dave, but I get this error in IE, FF is generating an error but i can't see what kind and firebug's console is empty. To be precise: using ff i don't get an internal error message, all I know is that my error function is invoked by the ajax call – Amir Aug 02 '11 at 14:22
  • When i used the url in FF with Firebug open I could see the internal server error 500 in firebugs Net tab and the error message in the browser, I just to repeated it but the service seems to be very slow at the moment. I can see the xml come back in the response for the valid getJSON example as well. Im not sure if you can use $.ajax with cross domain calls so just playing with that now. – Dave Aug 02 '11 at 14:33
  • I thought "jQuery.support.cors" would fix this since it changed the error from "no transport" to "inertnal error" (thats for IE, FF never specifies) currently firebug claims everything is ok (code 200) but the get line is colored red. this is weird but after some more digging I can guess it is a cross domain problem. – Amir Aug 02 '11 at 15:30
  • To sum things up... I dunno, I'll tray using some older methods not using jquery... :\ bah... – Amir Aug 02 '11 at 15:32
  • hi amir i added a suggestion at the end of my answer just in case we couldnt find away around it. – Dave Aug 02 '11 at 15:35
  • Looks like its on possible: http://stackoverflow.com/questions/923481/problem-with-calling-remote-asmx-using-jquery – Dave Aug 02 '11 at 16:24