tags:

views:

110

answers:

2

I know I can do an out of band Post request with Jquery and the $.post( syntax. However, I'm interested to know if it is possible for jquery to cause a post request on the whole page (as when a form is submitted) so that a brand new page is loaded. Is this possible?

Thanks

There is no form element in the DOM, so I can't do form.submit().

A: 

Not sure if I got your question, but if you just want to redirect the client after posting, just direct the client in the callback function of the $.post like

jQuery.post( url, {}, function() { location.href = "somewhere_else.html"; } )
Marco
Kind of - what I mean is, under a normal form post, the post parameters are sent to the server, and the server responds with an html document which replaces the current one. I would like to do the same thing with JQuery (so just one post to the server, not a post and then a seperate get, as your example would produce I think).
UpTheCreek
Oh, why don't you just post the form (without javascript) to that page and handle the request from there then? :) – Marco 0 secs ago
Marco
Because there is no form.
UpTheCreek
what about using jQuery to create a form and then post it :)?
marc.d
Oh, well if there is no form, I stand by my first reply, or what marc.d said.
Marco
A: 

I think you're trying to re-implement the default behaviour. Just use the regular submit mechanism the browser provides.

If you need to check the data before you actually submit it to the server, bind a function to the onsubmit event and do your checks, then either interrupt the submit action by returning false or return true and let the browser do all the work. Does this make sense to you?

Kaze no Koe