1

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?

Community
  • 1
  • 1
Gabriel R.
  • 303
  • 2
  • 15
  • 2
    it's always wise to check the data in the fron-end before seding it to the back-end, why not do that then? – Amin Jafari Nov 26 '15 at 21:43
  • I totally agree with you, but if I do that I will just avoid getting exceptions and won't find out why it is happening. I wan't to avoid the error, not to handle it – Gabriel R. Nov 27 '15 at 16:20
  • as you said in your question (if I understood correctly), it happens because some of the data aren't loaded while the ajax calls are being fired, so a way would be to write those ajax calls in a function, check the data in the function, if they were not what you wanted then loop the function and have it to start again with a little interval. – Amin Jafari Nov 28 '15 at 06:29
  • @AminJafari The issue that I am trying to solve isn't the exception that is thrown sometimes, what I am trying to solve is why is the data/DOM not being loaded correctly sometimes! (Since some exception have to be handled on the server side) – Gabriel R. Nov 30 '15 at 11:24

0 Answers0