12
3
|
I am kind of new to JavaScript library's. I wanted to replace my current code with a JS lib jQuery. My current code looks like this.
I wanted to replace my code with something a little friendlier like jQuery's
However I it doesn't call my callback function.
Also I would like to call this function createRequest to be called continuously. Does jQuery have a nice way of doing that?
| |||
| add comment |
19
|
should do the trick. Your callback could be simplified like this:
Or even shorter:
And all in all I think this should work:
| ||
| add comment |
3
|
Take out the readyState and status checks. jQuery only calls your callback upon success. Your callback is supplied the arguments
(data, textStatus), so you should use data instead ofreq.responseText.window.setTimeout() as suggested by another answer won't do what you want - that only waits and then calls your function once. You need to use window.setInterval() instead, which will call your function periodically until you cancel it.
So, in summary:
| |||
| add comment |
2
|
I don't think jQuery implements a timeout function, but plain old javascript does it rather nicely :)
| ||
| add comment |
2
|
A call to JavaScript's setTimeout function at the end of your callback function should suffice to get this to continually execute.
| ||||||||||||||||||||
|
1
|
There's no need to set the GET parameters on the URL, jQuery will set them automatically. Try this code:
| ||
| add comment |
0
|
In the end I guess it was added the type. This seems to work for me.
Thanks Everyone for the help. I'll vote you up.
| ||
| add comment |