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.

Recommended Answers

All 3 Replies

Member Avatar for diafol

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?

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

Member Avatar for diafol

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.