.ajax() can send a post request and get data in return where as .load() can get any element in the rendered page. How to create a form when submitted(asynchromously) instead of getting back some data should get the page element of the rendered page that would be generated had there been normal submission instead of ajax submission?
I dont want to write views(Django) for xhr, normal requests separately. So, When I submit a form by ajax I dont want to hijack default action but only want to get some element of the rendered post submission page instead of actually being redirected to that post submission page which would have happened hadn’t it been an xhr request.
Update:
loadwill do aPOSTrather than aGETif you supply the data to send as an object rather than a string. From the docs:So:
..should convert the
loadfromGETtoPOST. Of course, you’d replace{}with the arguments you want to send.Original answer:
You can do the
POSTdirectly withajaxand then process the returned HTML yourself. For instance, to turn thisload:..into a
POST:I’ve done the wrapper
divbecause that’s what jQuery’sloadfunction does. You may want to look at the source forload(that line number will rot, of course, but the filename is unlikely to change) to see if there are other tricks you need to replicate.