如何使用jquery将来自多个ajax请求的数据附加到html表中

如何使用jquery将来自多个ajax请求的数据附加到html表中,jquery,Jquery,这是我的密码。请看一下 var script = ""; $.ajax({ type: 'POST', url: url, contentType: 'application/json; charset=utf-8', dataType: 'JSON', success: function (data) { for(var i = 0; i < data.d.length; i++) { $.ajax({

这是我的密码。请看一下

var script = "";
$.ajax({
    type: 'POST',
    url: url,
    contentType: 'application/json; charset=utf-8',
    dataType: 'JSON',
    success: function (data) {
        for(var i = 0; i < data.d.length; i++) {
            $.ajax({
                type: 'POST',
                url: url,
                contentType: 'application/json; charset=utf-8',
                dataType: 'JSON',
                success: function (data1) {
                    script += data.d[i].date +"--"+data.d[i].name; // here date and name is my database columns
                },
                failure: function (response) {
                    alert("Fail");
                },
                error: function (response) {
                    alert("Error");
                }
            });
        }
        $("#Mytable").append(script);
    },
    failure: function (response) {
        alert("Fail");
    },
    error: function (response) {
        alert("Error");
    }
});

我从未尝试过类似的东西,但javascript是异步工作的。我认为当您在循环中发送请求时,循环不会等待任何响应,它将继续。当您的请求开始返回任何响应时,“i”可能达到data.d.length。因此data.d[i]是空引用


我应该再说一遍,我从来没有试过。只是我的意见。

请添加一些您的JSON,似乎您将获得没有日期类型的对象的日期。您能告诉我们成功函数中的数据是什么吗?或者可以使用jsoneditoronline.org查看JSON的层次结构,请稍候。我将向您展示我们需要的是您的JSON好友,而不是预期的输出。如果不查看您的json,我们将无法解析它。我如何向您显示我的json?实际上,我向c#发送请求并获取数据。
success: function (data1) {
$("#your_tr").html(data.d[i].date +'--'+data.d[i].name)
//script += data.d[i].date +"--"+data.d[i].name;
},
success: function (data1) {
$("#your_tr").html(data.d[i].date +'--'+data.d[i].name)
//script += data.d[i].date +"--"+data.d[i].name;
},