weixin_33738578 2011-11-05 20:48 采纳率: 0%
浏览 71

$ .ajax成功未执行

I have in my .js file a function that call a webservices method called getStudents:

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

the method is callled like:

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();
});

when i debug,the service web method is executed successfully but i don't get my alert('yes') and neither msg error.

What's wrong?

  • 写回答

1条回答 默认 最新

  • weixin_33698823 2011-11-05 21:32
    关注

    If you're returning (serialized to JSON) List of objects, then in response you will get JS array of JS objects, so (assuming Job has property p) try response[0].p for p value from first element.

    note: I don't know ASP.NET, so maybe response is serialized in another way, thats where tools like Firebug (or other browsers Dev tools) are extremely useful - because you can look how exactly you'r http requests and responses looks like.

    ps. And change alert to console.log and look for logs in Firebug console - its better than alert in many, many ways ;]

    评论

报告相同问题?

悬赏问题

  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)
  • ¥20 matlab yalmip kkt 双层优化问题
  • ¥15 如何在3D高斯飞溅的渲染的场景中获得一个可控的旋转物体
  • ¥88 实在没有想法,需要个思路
  • ¥15 MATLAB报错输入参数太多
  • ¥15 python中合并修改日期相同的CSV文件并按照修改日期的名字命名文件
  • ¥15 有赏,i卡绘世画不出
  • ¥15 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入