php - jquery AJAX function issue -
I am trying to run a function that executes a spinner while loading a PHP script And refreshes a PHP file that counts the number of rows inserted to show the progress of the script.
This is what I have done so far:
The progression () function starts yet, even if the button is not pushed even after the interval has ended, I believe that I should tie it with the spinner function But I am not completely sure how to do this work.
Edit: Here is the HTML that displays buttons and divisions:
& lt; div id = "stage" & gt; Click to import new data into the Assetata table & lt; P & gt; & Lt; div id = "spinner" & gt; & Lt; Img src = "/ images / spinner.gif" alt = "Loading ..." & gt; & Lt; / Div & gt; & Lt; Div id = "content" & gt; & Lt; / Div & gt; & Lt; P & gt; & Lt; Input type = "button" id = "driver" value = "load data" onClick = "this.disabled = true;" & Gt; & Lt; / Div & gt;
You should:
- Pages with buttons Load. When you upload the push button file
execute.php - After the user push button, the spinner is appearing and the AJAX request for the browser
progress.php starts requesting. - When
execute.php is uploaded, the spinner disappears, the progress result disappears. By doing this, the following jQuery code:
var myTimer; $ (Document) .ready (function () {// Primary function $ ("# driver"). Click (function (event) {$ .ajax ({url: 'http://api.openweathermap.org / Data / 2.5 / Forecast: Late = 35 End Loan = 139, Success: Function (Data) {// $ ("#someField"). Html (Data); // You execute `execute.php` The result of the $ ("#spinner"). $ ("#content"). Feedout ("sharp"); Clear interval (matimer);}, Error: Function (Bob) {// Show error console.log (' Get error '); clearInterval (myTimer);}, first send: function () {myTimer = setInterval (function () (/) {/ * // when you From the actual files and servers $ .ajax ({url: 'progress.php', success: function (data) {$ ("# content") .html (data);}}); * / $ ("# content" Connection ('Progress data'); console.log ('execute progress');}, 1); // change delay, when you create real files and server $ ("#spinner"). ; 'Console.log (' execute main function ');})}} P> See examples (this example for the code above), please Now, A what is required. right?
Do not forget to reduce some lines (AJAX request), change interval, remove debug output (for example, Line 29) etc.
Notice (and replace it when you use my code) url field execute.php ajax-requst. I used the weather API (just for example, you should change it in progress.php because this data takes some time to download, so that you can see the results. Remove the Weather URL and Progress for the URL .php . .
In addition, you can check the example. The code is pressed and This version allows the file to load and load after another. + setInterval + function progress looks better, I think. Hope this will help you.
Comments
Post a Comment