ebolt007 Posted March 24, 2012 Share Posted March 24, 2012 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 Quote Link to comment Share on other sites More sharing options...
ebolt007 Posted March 26, 2012 Author Share Posted March 26, 2012 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 Quote Link to comment Share on other sites More sharing options...
ebolt007 Posted March 27, 2012 Author Share Posted March 27, 2012 I fixed this, so a mod can close it, I had an error in my .php file, so it was echoing that instead of just the succes which is why it wasn't trying to do the refesh request. Quote Link to comment Share on other sites More sharing options...
Jessica Posted March 27, 2012 Share Posted March 27, 2012 I fixed this, so a mod can close it Use the SOLVED button. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.