I need to run a php script (site crawler) on submit button click without a page reload. After the background script run, A confirmation / alert popup should appear that the site crawler is ended. Any Ideas Please?
3
-
1Try Ajax, if you don't want to reload the page.GoSmash– GoSmash2012-04-17 06:06:36 +00:00Commented Apr 17, 2012 at 6:06
-
possible duplicate of How to run a php script in the background in another php script (like an update button)Amber– Amber2012-04-17 06:07:43 +00:00Commented Apr 17, 2012 at 6:07
-
A lot of information can be found here: api.jquery.com/jQuery.ajaxNiko– Niko2012-04-17 06:07:52 +00:00Commented Apr 17, 2012 at 6:07
Add a comment
|
2 Answers
Basically the idea goes like this:
- you send and XHR call to server and execute script
- script checks if there is already a background process
- if there is one, return the status code
- if on background script running: script forks itself , returns an "OK" response and start to do the work
- with a different XHR call you repeatedly check if script has finished
- when the server-side script has finished running, you gather the results and diplay in the page
To simplify the interaction with server, you might want to use some of the XHR libraries. I would avoid suggest to avoid slapping on jquery unless you are actually already using it for something else.
As for "how to know when background script has finished" : i think the best way would be for that script to create a file, which contains
- when running: -1
- when finished: 0
- when error: positive number
Comments
Jquery + AJAX could make your job easier. Read this tutorial on how to achieve the result: