-1

I am running a database query through javascript, and I want to display a message "Query is running" while the query statement is getting executed. But the message isn't getting displayed till the time the entire query is run. What would be the way to do this in javascript. I am a javascript beginner and self-learner, and i was unable to figure out away to do this. I googled but couldn't find anything useful. My code is:

function runThisQuery() {
     var connection = new ActiveXObject("ADODB.Connection"); 
     var rs = new ActiveXObject("ADODB.Recordset"); 
     var connectionstring="Provider=SQLOLEDB;Data Source=server;Initial Catalog=DB;Integrated Security=SSPI";
     connection.Open(connectionstring);

     //code till here is fine

     var dummyCell = document.createElement('td');
     dummyCell.setAttribute('id','dummyCell');
     var dummyCellText = document.createTextNode("running query");
     dummyCell.appendChild(dummyCellText);
     document.getElementById("mismatchSummaryRow").appendChild(dummyCell);

     rs.Open(runThisQuery, connection); //step A
}

The table cell that I am creating above, gets displayed only after the entire query (step A) is run. I want to display the message before the entire query (in Step A) is executed. what is the way to do this in JavaScript?

Rahul
  • 33
  • 2
  • 10
  • 1
    possible duplicate of [How can I create an Asynchronous function on Javascript?](http://stackoverflow.com/questions/9516900/how-can-i-create-an-asynchronous-function-on-javascript) – Farzher Apr 17 '15 at 19:59
  • 1
    I saw that, but the thing is i have never used jquery. wanted to find a way to do this through javascript directly – Rahul Apr 17 '15 at 20:01
  • @StephenBugsKamenar I'm not sure that's a duplicate of this; here, I suspect that the problem is that the native API that's being accessed *isn't* asynchronous. – Pointy Apr 17 '15 at 20:02
  • You're right, it's not duplicate. But I think the answers of the other question answer this question. You could just put `step A` in a `setTimeout`... or just move `step B` up 1 line? – Farzher Apr 17 '15 at 20:11
  • I don't understand why someone downvoted the question. What is the reason for that ????? – Rahul Apr 17 '15 at 20:49

1 Answers1

0

Got The Answer. [The person who downvoted the question, at least specify the reason for that. What's wrong with the question????]

Put the entire database fetching code in the setTimeout function.

function runThisQuery() {
   setTimeout(function() {
   var connection = new ActiveXObject("ADODB.Connection"); 
   var rs = new ActiveXObject("ADODB.Recordset"); 
   var connectionstring="Provider=SQLOLEDB;Data Source=server;Initial Catalog=DB;Integrated Security=SSPI";
   connection.Open(connectionstring);
   rs.Open(runThisQuery, connection);
   },1000);
var dummyCell = document.createElement('td');
dummyCell.setAttribute('id','dummyCell');
var dummyCellText = document.createTextNode("running query");
dummyCell.appendChild(dummyCellText);
document.getElementById("mismatchSummaryRow").appendChild(dummyCell);     
}
Rahul
  • 33
  • 2
  • 10