0

Edit There is something wrong as the inside of the .done callback does not execute, even a simple alert('something');

I've noted the error pointed out by Sverri I should note that this script is included externally, maybe that's the problem?

The login is successful, if I refresh the same page that I'm on, I am redirected by the PHP session catch at the top page. I'm trying to avoid having the login stuff for PHP on the same page as the form, but rather include it as a separate page.

When I process this, within the .done catch, the redirect does not work. I am logged in, the process works without errors. That's why when I refresh the same page(login) a session exists so I'm redirected by the php redirect.

$.post("login.php", { 'variable1':$variable1, 'variable2':$variable2 }).done(function() { window.location = "next-page-url"; } }); 

UPDATED

$.post("login.php", { 'variable1':$variable1, 'variable2':$variable2 }).done(function() { window.location = "next-page-url"; }); 
1

2 Answers 2

1

Your code has no major issue, as in just check other callback functions, like 'fail' or direct callback.

 <script> $(document).ready(function() { alert("hello"); $.post("/", { "var": "hello", "bar": "qwerty", }).done(function() { alert("hello !!"); }).fail(function() { window.location = "www.google.co.in"; }); }); </script> 
Sign up to request clarification or add additional context in comments.

3 Comments

whoa! It was a fail! How odd... I'll have to see the error.
I got it, I'm developing locally and it was an error regarding not using https, after transferring the same files to my VPS with an ssl certificate and https enabled, the success fired.
Good to know @janicehoplin
1

First off, your code is invalid. There is a } at the end, which shouldn't be there.

$.post("login.php", { // <- Open curly 'variable1':$variable1, 'variable2':$variable2 }).done(function() { // <- Close and open curly window.location = "next-page-url"; } // <- Close curly }); // <- Close curly (was never opened...) 

Try this instead:

$.post("login.php", { variable1: $variable1, variable2: $variable2, }).done(function() { window.location = "next-page-url"; }); 

As for it not going to the new page, see this answer.

2 Comments

I see that above I wrote it wrong but in my actual code, which looks just like you've shown, it doesn't work. I've tried both window.location.href and window.location. A simple alert('something'); works so it's executing properly. The redirect doesn't work.
Unfortunately I'm still not able to redirect. It seems that I actually am not able to trigger a simple alert() within the .done function despite being correct as far as syntax goes. Does something need to return from the login.php file? The login.php file executes without problems as I am logged in, but the inside of .done is not triggered... thoughts?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.