0

i have been able to pass value from form to ajax and to php to insert into my database. Now there is a value which determines whether to redirect to page 1 or page 2 after inserting. As well i alert that the form was successful. So i wanna know how to do pass this values back to ajax and how to redirect to the page i require.Thank you very much in advance.

2
Contributors
3
Replies
22
Views
1 Year
Discussion Span
Last Post by diafol
0

Using Ajax to redirect (php-wise) will not work. The Ajax is basically a js-driven script causing certain things to happen on the server, which the client (js) is oblivious to. The js script is informed of the status of the msg and any data sent from the server. The fact that you hit a redirect on the server means nothing to the js script unless that redirected page returns data (echo). If you want to do a redirect, then you do a js redirect, e.g.

window.location.replace("whatever...url?page=" + pageNumber);

pageNumber being the page 1 or 2 or of course you could map numbers to pagenames.
If you're actually going to redirect when you submit a form, why use ajax at all? This sort of defeats the object doesn't it?

0

So pls if i want to just post with ajax and redirect from the php file.what shpuld i do pls. examples will be welcomed.thanks

0

OK, I'll try to make myself understood better - why do you need to submit using Ajax if you are redirecting to a new page? The whole point of Ajax is that you can perform back-end operations and/or update parts of a page without redirect.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.