Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
多个ajax调用jquerymvc_Jquery_Asp.net Mvc_C# 4.0 - Fatal编程技术网

多个ajax调用jquerymvc

多个ajax调用jquerymvc,jquery,asp.net-mvc,c#-4.0,Jquery,Asp.net Mvc,C# 4.0,我正在开发一个打印页面,其中我们必须显示所有的报告和图表 每个客户的图表数量不同。 因此,我为每个可用图编写jquery脚本,如下所示: buildJQs: function () { $(".emailgraphs").each(function () { YAHOO.Report.Print("Email", $(this).attr("responsefield"), $(this).attr("id"), $(this).attr("metric

我正在开发一个打印页面,其中我们必须显示所有的报告和图表

每个客户的图表数量不同。 因此,我为每个可用图编写jquery脚本,如下所示:

buildJQs: function () {

        $(".emailgraphs").each(function () {
            YAHOO.Report.Print("Email", $(this).attr("responsefield"), $(this).attr("id"), $(this).attr("metricid"))
        });
    },

Print: function (name, graphid, divid, metricid) {

        try {
            $.ajax({
                type: "POST",
                contentType: "application/json; charset=utf-8",
                url: m_oReport.ds,
                async: false,
                timeout: 300,
                data: JSON.stringify(m_oReport.printp(name, graphid, metricid)),
                beforeSend: function () {
                    //Displays loading image before request send, till we get response.
                    //$("#" + divId).addClass("loading");
                },
                cache: false,
                success: function (data) {
                    // if they define a success function (s), call it and return data to it.
                    if (typeof m_oReport.prints === "function") {
                        //$("#" + divId).removeClass("loading");

                        m_oReport.prints(data, divid, name, metricid)
                    }
                },
                error: function (err) {
                    $("#" + divid).html(err);
                }
            });
        }
        catch (err) { alert("catch"); }
    }
问题是,控制器返回的数据没有任何问题,但当我将其分配给jqplot时,数据变为空。我认为这是由于异步ajax调用造成的。我尝试了async:false和timeout,但仍然面临这个问题

有没有办法处理这个问题


提前感谢…

请使用jquery Deliver尝试以下操作:

buildJQs: function () {

    var deferreds = [], deferred;
    $(".emailgraphs").each(function () {

        deferred = YAHOO.Report.Print("Email", $(this).attr("responsefield"), $(this).attr("id"), $(this).attr("metricid")); 
        deferreds.push(deferred);
     });

     $.when.apply(null, deferreds).done(function() {
         alert('all done');
     });
},

Print: function (name, graphid, divid, metricid) {

        try {
           return $.ajax({
                type: "POST",
                contentType: "application/json; charset=utf-8",
                url: m_oReport.ds,
                //async: false, <- remove, this is a problem
                timeout: 300,
                data: JSON.stringify(m_oReport.printp(name, graphid, metricid)),
                beforeSend: function () {
                    //Displays loading image before request send, till we get response.
                    //$("#" + divId).addClass("loading");
                },
                cache: false,
                success: function (data) {
                    // if they define a success function (s), call it and return data to it.
                    if (typeof m_oReport.prints === "function") {
                        //$("#" + divId).removeClass("loading");

                        m_oReport.prints(data, divid, name, metricid)
                    }
                },
                error: function (err) {
                    $("#" + divid).html(err);
                }
            });

        }
        catch (err) { alert("catch"); }
        return null; 
    }
buildJQs:function(){
风险值递延=[],递延;
$(“.emailgraphs”)。每个(函数(){
deferred=YAHOO.Report.Print(“Email”)、$(this.attr(“responsefield”)、$(this.attr(“id”)、$(this.attr(“metricid”);
推迟。推送(推迟);
});
$.when.apply(空,延迟).done(函数(){
警报(“全部完成”);
});
},
打印:函数(名称、图形、divid、metricid){
试一试{
返回$.ajax({
类型:“POST”,
contentType:“应用程序/json;字符集=utf-8”,
url:m_oReport.ds,

//async:false,使用jquery延迟尝试以下操作:

buildJQs: function () {

    var deferreds = [], deferred;
    $(".emailgraphs").each(function () {

        deferred = YAHOO.Report.Print("Email", $(this).attr("responsefield"), $(this).attr("id"), $(this).attr("metricid")); 
        deferreds.push(deferred);
     });

     $.when.apply(null, deferreds).done(function() {
         alert('all done');
     });
},

Print: function (name, graphid, divid, metricid) {

        try {
           return $.ajax({
                type: "POST",
                contentType: "application/json; charset=utf-8",
                url: m_oReport.ds,
                //async: false, <- remove, this is a problem
                timeout: 300,
                data: JSON.stringify(m_oReport.printp(name, graphid, metricid)),
                beforeSend: function () {
                    //Displays loading image before request send, till we get response.
                    //$("#" + divId).addClass("loading");
                },
                cache: false,
                success: function (data) {
                    // if they define a success function (s), call it and return data to it.
                    if (typeof m_oReport.prints === "function") {
                        //$("#" + divId).removeClass("loading");

                        m_oReport.prints(data, divid, name, metricid)
                    }
                },
                error: function (err) {
                    $("#" + divid).html(err);
                }
            });

        }
        catch (err) { alert("catch"); }
        return null; 
    }
buildJQs:function(){
风险值递延=[],递延;
$(“.emailgraphs”)。每个(函数(){
deferred=YAHOO.Report.Print(“Email”)、$(this.attr(“responsefield”)、$(this.attr(“id”)、$(this.attr(“metricid”);
推迟。推送(推迟);
});
$.when.apply(空,延迟).done(函数(){
警报(“全部完成”);
});
},
打印:函数(名称、图形、divid、metricid){
试一试{
返回$.ajax({
类型:“POST”,
contentType:“应用程序/json;字符集=utf-8”,
url:m_oReport.ds,

//async:false,如果有助于检查此项,如果有助于感谢您的响应,请检查此项。但是,始终从行中未定义延迟项--deferred=YAHOO.Report.Print(“Email”),$(this.attr(“responsefield”),$(this.attr(“id”),$(this.attr(“metricid”);deferreds.push(deferred);您使用的是什么版本的jQuery?为什么使用
try
catch
YAHOO.Report.Print
Print:function(name、graphid、divid、metricid)
?这已解决,请查看其他帖子,不确定async=false最初不起作用的原因,但现在它起作用了。好的,我没有看到设置了该选项,这是一个问题,因为您必须等待完成每个调用才能继续下一个调用。最好是异步并处理事件或解除,尝试更改以尝试或删除此选项,然后重试试试我的例子。谢谢你的回复。但是总是从行中得到未定义的延迟——deferred=YAHOO.Report.Print(“Email”、$(this.attr(“responsefield”)、$(this.attr(“id”)、$(this.attr(“metricid”);deferreds.push(deferred);您使用的是什么版本的jQuery?为什么使用
try
catch
YAHOO.Report.Print
Print:function(name、graphid、divid、metricid)
?这已解决,请查看其他帖子,不确定async=false最初不起作用的原因,但现在它起作用了。好的,我没有看到设置了该选项,这是一个问题,因为您必须等待完成每个调用才能继续下一个调用。最好是异步并处理事件或解除,尝试更改以尝试或删除此选项,然后重试试试我的例子。