开发者

Internal Error 500 when accessing a webservice using jquery

开发者 https://www.devze.com 2023-03-24 08:01 出处:网络
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 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 sin开发者_开发知识库ce the web service is remote. (without this line I get "No Transport" error)


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号