当javascript循环运行时,htmlButtons不起作用 [英] htmlButtons are not working when javascript loop is running

查看:75
本文介绍了当javascript循环运行时,htmlButtons不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个网格,网格下面有一个按钮。在按钮单击中我正在处理网格数据。由于某种原因,我逐个从网格中收集keyfield值并转到服务器,对keyfield做一些操作并返回给客户端。我正在使用javascript做这个工作。我需要在处理中弹出一个弹出窗口,我需要在进程更新期间向用户显示一些信息。在javascript循环的每次迭代中,弹出窗口中的信息在从服务器传出时发生更改。



我使用ajax发布数据并调用web方法(驻留在我的aspx页面中)。这很好。现在在处理期间,我想取消该过程。所以我在弹出窗口中放了一个取消按钮。但是随着javascript循环的进展,我无法在弹出窗口中单击按钮直到整个过程完成。如果我使ajax调用异步,那么我可以这样做,但由于调用是异步的,我在弹出窗口中显示的信息是错误的或过时的。因此,我需要同步调用服务器,并为用户提供一个选项,他可以在中途取消该过程。他不需要结束这个过程或类似的事情。



请帮助我。







我的js代码:



I have a grid, below the grid there is a button. In the button click I am processing the data of grid. Due to some reason I collect keyfield value form the grid one by one and go to the server, do some operation against the keyfield and return back to the client. I am doing this job using javascript. i need a popup in the processing where I need to show some information to the user during the process update. At each iteration of javascript loop the information in popup is changed as they are comming from server.

I am posting the data using ajax and calling a web method(residing in my aspx page). Upto this It is fine. Now during the processing time, I want to cancel the process. So I put a cancel button in the popup. But as things going in javascript loop I can not click the button in popup upto the entire process is complete. If I make the ajax call asynchronous, then I can do it, but as the call is asynchronous the informations I am displaying in popup are wrong or back dated. So I need to synchronouly call to server and also give the user a option that he can cancel the process in the middle of the way. He need not go the end of the process or something like that.

Please healp me.



my js code :

function CreateWO(s, e) {

$("#hdnCancelWorkOrder").value = "0";
$("#htmlLabelhiddenField").innerHTML = "";
var jsonText;
$("#show1").show(); //showing the popup



//loop
for (var index = grdBatchRecord.GetTopVisibleIndex(); index < grdBatchRecord.GetVisibleRowsOnPage(); index++)

{

var keyval = grdBatchRecord.GetRowKey(index);

if ($("#hdnCancelWorkOrder").value == "1")

{
$("#show1").hide();
$("#hdnCancelWorkOrder").value = "0";
break;
}

jsonText = JSON.stringify({ keyval: keyval });
$.ajax({
type: "POST",
url: "PreventiveMaintenanceWorkOrderGeneration.aspx/ProcessWO",
data: jsonText,
contentType: "application/json; charset=utf-8",
dataType: "json",
async: false,
success: function (msg) {
document.getElementById("htmlLabelProcessingIndex").innerHTML = msg.d;

}
});

//alert(keyval);
}
document.getElementById('htmlLabelWOComplete').innerHTML = "Work Order Generation Process is complete.";
//$("#show1").hide();
}


function closeDiv() {
$("#show1").hide();
$("#hdnCancelWorkOrder").value = 1;
}

function CancelProc() {
$("#hdnCancelWorkOrder").value = 1;
}

推荐答案

#hdnCancelWorkOrder)。value = 0;
("#hdnCancelWorkOrder").value = "0";


#htmlLabelhiddenField)。innerHTML = ;
var jsonText;
("#htmlLabelhiddenField").innerHTML = ""; var jsonText;


#秀王 )表示(); // 显示弹出窗口



< span class =code-comment> //
loop
for var index = grdBatchRecord.GetTopVisibleIndex(); index< grdBatchRecord.GetVisibleRowsOnPage(); index ++)

{

var keyval = grdBatchRecord.GetRowKey(index);

if
("#show1").show(); //showing the popup //loop for (var index = grdBatchRecord.GetTopVisibleIndex(); index < grdBatchRecord.GetVisibleRowsOnPage(); index++) { var keyval = grdBatchRecord.GetRowKey(index); if (


这篇关于当javascript循环运行时,htmlButtons不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆