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

时间:2011-09-07 05:47:35

标签: ajax jquery

我想从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);
            }
        });

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

1 个答案:

答案 0 :(得分:1)

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

来调试ajax调用
error : function(xhr,status,error){
    alert(status);
},
相关问题