Jump to content

Send Login to ne page using php header in my ajax php file.


ebolt007

Recommended Posts

Ok, so how do I send the URL to a new page? Right now I understand the writing ajax to a div, replacing the contents of the div, appending it etc. But what about if I am using the below code, for like a login area, I can get the form to return wrong username etc based on the submitting, but if everything checks out as correct in my ajax-login.php file, the form doesn't follow the headers at the bottom of the page. What would I use to make it follow the headers from this page? Or is there a better way?

Thanks

ajax-login.php

a bunch of code, grabbing the values from the form and checking if they are valid passwords and things like that like;
if ($usernamecheck == ''){
  echo "<div id=\"log_res2\">";
	echo "<span class=\"error\">*Must enter a username.</span><br />";
	  echo "</div>";
  }else{
header("location: /index.php");
}

 

And my ajax is

$(document).ready(function()
{
$("#Login").click(function(){


var $password = $("#password").val();
var $username = $("#username").val();

var dataString = 'username=' + $username + '&password=' + $password;


$.ajax({
type: "POST",
url: "../includeajax/ajax-login.php",
data: dataString,
cache: false,
success: function(html){
$("#log_res2").replaceWith(html);
}
});


return false;
});
});

 

I get the errors when I put in the wrong usernames or passwords, but how do I return that header to make it redirect to a new page?

Thanks

Ok, so I have modified my code a little, so the php file now echo's success when t's complete, and I now want it to load the index page again. My cookies get set and everything, but when I try to use

 

if(html == 'success'){

  window.location.replace('http://www.thetrue1.com');
  
}else{
$("#log_res2").replaceWith(html);
}

 

it doesn't reload the page, it just sits there. but if I hit refresh, then the user is logged in correctly, so how do I use window.location.replace('http://www.thetrue1.com'); to refresh my page? My errors and everything else are working perfectly.

Thanks

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.