第一次尝试时异步发布失败,第二次失败

时间:2018-05-18 07:33:26

标签: javascript ajax vb.net asynchronous

我想从数据库中检索一个值,但似乎我的ajax_update2()函数读取以前的数据而不是当前数据。在致电async:false之前,我在runMon2()设置了ajax_update2()。它只在第二次工作。

注意:我正在使用IE11。

function runMon2() {
   $("#btnStop").show();
   $("#btnStart").hide();
   $("#msgz").html("");

   $.ajax({
      type: "POST",
      url: "stage2.aspx/s3_monte_carlo_run_thread",
      data: '{id: "' + <%= id%> + '",no_cycles:"' + $("#cycles").val() + '",covSmys:"' + $("#covSmys").val() + '",covT:"' + $("#covT").val() + '",covL:"' + $("#covL").val() + '",covD:"' + $("#covD").val() + '", D:"' + <%= D%> + '",L: "' + <%= L%> + '",T: "' + <%= T%> + '",Pa: "' + <%= Pa%> + '",UTS: "' + <%= UTS%> + '",SMYS: "' + <%= SMYS%> + '",assess_type:"' + $("#assess_type").val() + '",year: "' + <%=year%> + '" }',
      dataType: 'json',
      async: false,
      contentType: "application/json; charset=utf-8",
      success: function (data) {
            successmessage = 'RunMon2 Successfully enter data';
            $("#progressbar").show();
            $("#msgz").show();
            setTimeout(ajax_update2(), 50000);
              },
       fail: function (data) {
            successmessage = 'RunMon2 Operation Failed';
            console.log(successmessage);
              },
          });

      }

function ajax_update2() {
    $("#btnStop").show();
    $("#btnStart").hide();
    console.log("ajax_update2");

    $.ajax({
        type: "POST",
        url: "stage2.aspx/s3_monte_carlo_refresh",
        data: '{id: "' + <%= id%> + '"}',
        dataType: 'json',
        contentType: "application/json; charset=utf-8",
    })
        .done(function (data) {
        data = $.trim(data.d);
        console.log(data)
        if (data == "") {
            $("#msgz").hide();
            $("#btnStart").show();
            $("#btnStop").hide();
            console.log("data empty");
            return;
        }
        var dd = data.split("!");
        var temp = data.d;
        if (parseFloat(dd[0]) == 100) {
            $("#progressbar").hide();
            $("#msgz").html(dd[1]);
            $("#btnStop").hide();
            $("#btnStart").show();
            console.log("data complete");
            return;
        }

        $("#progressbar").progressbar("option", "value", parseFloat(dd[0]));
        $("#msgz").html(dd[1]);
        setTimeout("ajax_update2()",5000);
        successmessage = 'Successfully enter ajax_update2';
        console.log(successmessage);
    });
}

0 个答案:

没有答案
相关问题