I have a generic issue that happens intermittently when sending data of a DOM element to the server through AJAX and I cannot find a way to reproduce them.
There are a bunch of pages that send data from the DOM (like $("#id").val()
or $("#form").serialize()
) through AJAX and in some cases users throws exceptions like:
"Cannot convert id 'undefined' to Long" - when trying to manipulate an id that should be a number
"page is not present" - when Spring MVC Controllers try to use the data sent from a form (related)
One way I was able to reproduce some of these cases was by bursting a lot of page refreshes on pages that have an AJAX call fired on page load, but not on pages that have AJAX calls on user interactions (like a button click).
I am really confused with this issue, because if I switch from $(document).ready()
calls to $(window).load()
I won't get exceptions on the pages that have AJAX calls on page load, but this is not the right way to solve it for this case, since I don't want/have to wait scripts and images to load and it doesn't solve the problem for pages that have AJAX bound to user events.
I assume that the server is always sending the correct DOM to users (since I was never able to reproduce most cases), so what can be happening to get those exceptions?