Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:

JavaScript
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");
                                    }

                                });
Posted
Updated 17-Feb-16 22:18pm
v2
Comments
Sinisa Hajnal 15-Feb-16 3:12am    
Try setTimeout function
Member 7909353 15-Feb-16 3:38am    
setTimeout function executes one statement or function after some time it does not stop execution of next statement for some time.
I want to execute statement after execution of function().
F-ES Sitecore 15-Feb-16 5:49am    
Don't really understand the issue\code, you haven't said what is in bindGridView, but your problem will probably be solved using non-asynchronous ajax calls, so set

async: false

when you use $.ajax

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.
 
Share this answer
 
Comments
Richard Deeming 15-Feb-16 10:42am    
If you mean the "custom alert" question, that was a different user asking effectively the same question. :)
It is not possible bcoz javascript is single thread language.

It is not possible to call generic handler to communicate with database( or u can say IS) bcoz calling of this,is one statement in javascript.
So below code is not possible in for loop
JavaScript
$.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");
                                    }
 
                                });
Improve question   Permalink   
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900