jQuery Ajax Response:成功时将响应视为null

时间:2022-08-06 20:19:00

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.

我想从jQuery .ajax()调用我的机器本地托管的.net webservice。该脚本包含在静态.html文件中。触发成功函数但响应数据为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().append(msg);
            }
        });

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

当我提醒响应它给我NULL时,任何人都可以告诉我我的错误,谢谢你提前。

1 个解决方案

#1


1  

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

这是因为您可能从静态页面调用ajax,该页面不在http:// localhost:60931 /中。您可以将静态html放在localhost中并尝试通过相同的URL运行它。或者你可以通过添加来调试你的ajax调用

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

#1


1  

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

这是因为您可能从静态页面调用ajax,该页面不在http:// localhost:60931 /中。您可以将静态html放在localhost中并尝试通过相同的URL运行它。或者你可以通过添加来调试你的ajax调用

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