I don't think DanInMa's change will help find the problem.
True, it will show that what is coming back from the AJAX call is not a number greater than zero, but the real root of the problem is almost surely in the PHP code that is sending back that bad number.
I think the more important thing is to find out what the URL is that is being used when the error occurs.
So to that end, I'd add a debug line here:
alert("Calling AJAX with url: " + url);
Then, when the failure occurs, open up another browser window or tab and hit that same URL directly from the browser, so you can see what the PHP code is doing (it will, presumably, display a number <= 0, and possibly error messages). And then start debugging the PHP code.