I'm using javascript to submit a form to a webservice which returns a json object.
Is there a way to get the json object using javascript after calling form.submit() (without navigating away from the page)?
I know you can make an ajax 'post' call, but if possible, I'd like to avoid that since it's simpler to just let html form actions do the d开发者_StackOverflow中文版irty work especially since I'm doing file uploads.
More background:
I have a page with lots of image upload forms, I want to upload each of those images individually and then display the uploaded url (which is returned as part of the json object).
p.s. jquery solutions are welcome :)
You cannot do file uploads via AJAX. Use the jQuery forms plugin to manage the form/submission and read the notes about uploads.
It does all the annoying stuff like dealing with iframes automatically in the background and you just have to add textarea tags around your json response.
You can upload file using Ajax and Iframe, without refreshing the page, it's a little tricky, but works fine and I'm using it well :)
http://www.openjs.com/articles/ajax/ajax_file_upload/
hope it helps.
精彩评论