开发者

jQuery Ajax Response: getting response as null on success

开发者 https://www.devze.com 2023-04-03 08:13 出处:网络
I wanted to invoke a .net webservice which is hosted locally on my machine from jQuery .ajax(). the script is included in the static .html file.

I wanted to invoke a .net webservice which is hosted locally on my machine from jQuery .ajax(). the script is included in the static .html file. the success function is triggered but the response data is NULL.

        $.ajax({
            type: "GET",
            data: '{continent: "' + $('#txtContinent').val() + '"}',
            url: "http://localhost:60931/Service1.asmx/GetCountries",

            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function(response) {

            alert(response);

            },
            failure: function(msg) {

                $('#result').empty().app开发者_StackOverflow社区end(msg);
            }
        });

When i alert the response its giving me NULL, can anyone tell me where im goin wrong, Thanks in advance.


Its because you might be calling the ajax from a static page which is not in http://localhost:60931/. You can put the static html in the localhost and try to run it via the same url. Or you can debug your ajax call by adding

error : function(xhr,status,error){
    alert(status);
},
0

精彩评论

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