如何在javascript中停止执行一段时间 [英] How to stop execution of line for some time in javascript
本文介绍了如何在javascript中停止执行一段时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个var MYTable,在这个MYTable中我想添加表格。
当我调用BindGridView()函数来更新MYTable时,在下一个语句中我进一步更新了MYTable。
当我执行警报时它很好但没有警告它不会在调用函数时更新MYTable。
在BindGridView()函数中,我从数据库中调用html表。
我尝试过:
var MYTable = ' 跨度>;
for ( var i = 0 ; i< 10; i ++)
{
var MYTable + = < tr>< td>< table>;
MYTable + = < tr>< td> + i + < / td>< / tr>;
BindGridView();
// alert(MYTable2 =+ MYTable);
var MYTable + = < / td>< / tr> ;< /表>< / TD>< / TR GT&;跨度>;
}
$ .ajax({
类型: POST,
contentType: application / json; charset = utf-8 ,
url: ../ scm / Search_CS.ashx?act = bg& FPSNo = + FPSCodearr [i] + & commodityId = + comm [ 1 ] + & month = + my [ 1 ] + & AllocNo = + $(' #<%= ddl.ClientID%>:selected')。text(),
data: {},
dataType: json,
async: true ,
成功: function (结果){
},
错误: function (){
alert( 错误);
}
});
解决方案
.ajax({
类型: POST,
contentType: application / json; charset = utf-8,
url: < span class =code-string> ../ scm / Search_CS.ashx?act = bg& FPSNo = + FPSCodearr [i] + & commodityId = + comm [ 1 ] + & month = + my [ 1 ] + & AllocNo = +
( ' #&l t;%= ddl.ClientID%> :选中')。text(),
数据: {},
dataType: json,
async: true ,
成功:功能(结果){
} ,
错误: function (){
alert( 错误跨度>);
}
});
正如您在其他问题中提到的那样,您无法停止执行。你必须调用一个新函数。
但是,F-ES是对的,不清楚你在说什么,但是设置async:false可能会给你你想要的东西
I have a var MYTable ,in this MYTable I want to add tables.
When I call BindGridView() function for updating MYTable and in next statement I further update MYTable.
When I execute alert it is fine but without alert it will not update MYTable in calling function.
In BindGridView() function, i call html table from database.
What I have tried:
var MYTable='';
for(var i=0;i<10;i++)
{
var MYTable += "<tr><td><table>";
MYTable += "<tr><td>" + i + "</td></tr>";
BindGridView();
//alert("MYTable2=" + MYTable);
var MYTable += "</td></tr></table></td></tr>";
}
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "../scm/Search_CS.ashx?act=bg&FPSNo=" + FPSCodearr[i] + "&commodityId=" + comm[1] + "&month=" + my[1] + "&AllocNo=" + $('#<%=ddl.ClientID %> :selected').text(),
data: "{}",
dataType: "json",
async: true,
success: function (result) {
},
error: function () {
alert("Error");
}
});
解决方案
.ajax({ type: "POST", contentType: "application/json; charset=utf-8", url: "../scm/Search_CS.ashx?act=bg&FPSNo=" + FPSCodearr[i] + "&commodityId=" + comm[1] + "&month=" + my[1] + "&AllocNo=" +
('#<%=ddl.ClientID %> :selected').text(), data: "{}", dataType: "json", async: true, success: function (result) { }, error: function () { alert("Error"); } });
As you asked in a different question, you cannot stop the execution. You have to call a new function.
However, F-ES is right, it is unclear what you are saying but setting async: false may give you what you want.
这篇关于如何在javascript中停止执行一段时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文