Using Jquery to check if a URL is valid
A long running background process creates a text file to indicate the completion of the process. From the frontend, I'd need to check every few seconds if the text file has been created or not.
I am doing this check from http://DomainA.com
However the file is created in http://DomainB.com/Mytext.txt
Can someone help me write a jquery script that checks for a file across domain?
PS: Currently, I am doing a ajax postback that executes a WebMethod
in ASP.NET that creates HttpWebRequest
. This works functionally, but I have major开发者_运维技巧 performance problems. So, I need a light weight way of finding if a URL is valid or not.
Thanks
I would set up a server-side script on your own server which pings the URL (using cURL or whatever) and responds with a JSONified version of the response.
Do not fire HttpWebRequest
at the moment the jQuery script requests it. Run HttpWebRequest
independently at same intervals in some background thread which in turn sets some shared boolean toggle. Finally let the code which should respond to jQuery requests return the state of this toggle (thus without firing the HttpWebRequest
itself).
I ended up using YQL with JQuery that lets me do cross domain requests.
call it using jQuery ajax, then look at the result if it is 404? This is asynchronous though, so you need to use javascript continuations if you are in a workflow
精彩评论