I am using jQuery and sending a post request to a page which sends back an JSON Array. In the method I am doing the post request I fire another function/Controller which then displays a form (html file) which I load via get and then fills the form fields of the form with the values from the json object returned by the first post request. The issue is, that because the post Request from jQuery is async, the loading of the html file is slower than the next line which fills the form which means no form fields are filled with the values.
Can someone give me an exmaple how I should do this kind of things in jQuery ? If you need I post an example snippet I use right now, if something is not clear.
I know jQuery supports disabling of async requests but this is deprectaed in v1.8 which is why I don’t want to use it…
Thanks in advance!
What you’re going to need is to use a callback in the initial ajax call to call the form-filling line. This will ensure that the form-filling line is executed only on successful completion of the ajax process.
Check out either the
success()orcomplete()methods on http://api.jquery.com/jQuery.ajax/. If you post code, I can help you fill it out.