Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I feed back current progress of code behind process to UI from jQuery AJAX call
    primarykey
    data
    text
    <p>I have a form that is going to be executing a failry long running process. Not just long, but many small steps during an install process. I'm trying to stay away from using the built in MS AJAX as much as possible in my entire application, but will use it on this page if it's just the easier way to do things.</p> <p>But what I want is to only one jQuery AJAX call to code behind and have code behind spit out progess as it hits each step. Here is what I've gotten so far. It's just sample code but it's what I'm trying to do. </p> <p>UI:</p> <pre><code>&lt;head runat="server"&gt; &lt;title&gt;&lt;/title&gt; &lt;script type="text/javascript"&gt; $(function() { $(this).find("#submitForm").click(function() { RunCodeBehind(); }); }); function RunCodeBehind() { $.ajax({ error: function(msg) { alert(msg) }, type: "POST", url: 'Other.aspx/RunLongRunningProcess', data: "{}", contentType: "application/json; charset=utf-8", dataType: "json", success: function(responses) { if (responses.d != "") { //Display process in UI var divEvents = document.getElementById("events"); divEvents.innerText = divEvents.innerText + "\n" + data; } else { //no response, update as failed var divEvents = document.getElementById("events"); divEvents.innerText = divEvents.innerText + "No response from code behind"; } } }); } &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;form id="form1" runat="server"&gt; &lt;div&gt; &lt;a id="submitForm"&gt;Start Process&lt;/a&gt; &lt;br /&gt; &lt;div id="events"&gt;&lt;/div&gt; &lt;/div&gt; &lt;/form&gt; &lt;/body&gt; </code></pre> <p>Code behind:</p> <pre><code>[WebMethod] public static string RunLongRunningProcess() { string returnValue; var sqlQuery = "SELECT COUNT(*) FROM Users;"; //generic sql query returnValue = ExecuteQuery(sqlQuery); //feedback cout total to UI, continue process var sqlQueryInsert = @"INSERT INTO Log (UserCount) SELECT COUNT(*) FROM Users;"; //generic sql insert returnValue = ExecuteNonQuery(sqlQueryInsert); //feedback insert step to UI var sqlQuery = "SELECT user + ' - ' + name + ' - ' + favday FROM Users;"; //generic sql query returnValue = ExecuteQuery(sqlQuery); //feedback selection to UI return returnValue; } </code></pre> <p>Any pointers on how to make it feed back to the UI more than once with just a single call?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload