NYCPHP Meetup

NYPHP.org

[nycphp-talk] the stale V in MVC web apps

John Campbell jcampbell1 at gmail.com
Wed Mar 4 13:30:05 EST 2009


On Wed, Mar 4, 2009 at 12:48 PM, David Mintz <vtbludgeon at gmail.com> wrote:
> // on load
>
> window.updater = window.setInterval(submitForm,updateInterval);
>
> // and...
>
> submitForm = function(){
> 	
> 	$('searchForm').request({
> 		onCreate:function(response){$('formSubmit').value="Processing..."},
>
> 		onComplete:function(xhr){
> 			// reset timer
>   			window.clearInterval(updater);
>   			window.updater = window.setInterval(submitForm,updateInterval);
> 			$('formSubmit').value="Search" // reset button's value
>
> 			// etc
> 			
> 		}
> 	});
> 		
> };

I don't think your code is quite right.  To validate polling code,
just add "sleep(2)" to your php code, and set the updateInterval to 1
second.  If it doesn't work under these conditions, then the code is
not quite right.

The problem with your code is that you clear the interval onComplete,
rather than onCreate.  It is possible that the interval keeps firing
while onComplete has not been run because the ajax requests are taking
a long time due to a network issue.

To fix it... just change setInterval to setTimeout everywhere, and get
rid if the clearInterval code.



More information about the talk mailing list