Is it possible using jQuery to change the page URL while passing post data to the new page?
A:
If you mean that you want to change the current page URL, well then you can add a new <form>
to the current page, add hidden input elements to it, and then submit it.
$('body').append($('<form/>')
.attr({'action': yourNewURL, 'method': 'post', 'id', 'replacer'})
.append($('<input/>')
.attr({'type': 'hidden', 'name': 'param1', 'value': "hello"})
)
.append($('<input/>')
.attr({'type': 'hidden', 'name': 'param2', 'value': "world"})
)
).find('#replacer').submit();
Or something like that.
Pointy
2010-03-02 23:18:26
Is it possible to use jQuery.ajax?
Brian
2010-03-02 23:22:14
Well if you want to replace the whole page anyway, what's the point of Ajax?
Pointy
2010-03-02 23:30:18
Could I use .load?
Brian
2010-03-03 00:11:21
@Brian - You want to **change pages**, ajax is specifically to prevent **changing pages**. What you want is a form with an action that goes to the new page, nothing more. You don't even need a lick of javascript to do this either, just a `<form action="/Page2" method="POST">`
Nick Craver
2010-03-03 02:05:36
A:
If you are POSTing data not in a form (because you could simply set the form's action to the current page) and the data being posted isn't directly related to the content of the next page, you can use the callback function of jQuery's .post() method to redirect the user:
$.post( '/Page2', { 'foo' : 'bar' }, function() {
window.location.href = '/Page2';
});
This seems like an unlikely situation, maybe you could comment with more details about the data being passed and its relation to the content of Page2?
tb
2010-03-02 23:28:03