$ .ajax成功没有执行

时间:2011-11-05 20:48:31

标签: asp.net ajax json jquery

我的.js文件中有一个函数,它调用一个名为getStudents的webservices方法:

    [WebMethod(Description = "white student list")]
    [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
    public List<Job> getStudents(long classId)
    {
        return (new classManager()).getStudents(classId);
    }

该方法被调用如:

function loadStudents() {

    var parameters = JSON.stringify({ 'classId': 0 });

    alert(parameters);

    $("#ProcessingDiv").show('fast', function() {
        $.ajax({
            type: "POST",
            url: "myWebService.asmx/getStudents",
            data: parameters,
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function(response) {
                  $("#ProcessingDiv").hide();
                  var students= response.d;
                  alert('yes');
            },

            error: function(request, status, error) {
                alert(request.responseText);
            }
            ,
            failure: function(msg) {
                alert('somethin went wrong' + msg);
            }
        });
    });
}
$(document).ready(function() {

    loadStudents();
});

当我调试时,服务web方法成功执行但我没有收到警报('是')并且没有msg错误。

怎么了?

1 个答案:

答案 0 :(得分:0)

如果您正在返回(序列化为JSON)对象列表,那么作为响应,您将获得JS对象的JS数组,因此(假设Job具有属性p)尝试{{1}来自第一个元素的response[0].p值。

注意:我不知道ASP.NET,所以也许反应是以另一种方式序列化的,那就像Firebug(或其他浏览器开发工具)这样的工具非常有用 - 因为你可以看看您的http请求和响应究竟如何。

ps。并将p更改为alert并在Firebug控制台中查找日志 - 它在很多方面都优于console.log;]

相关问题