Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6546773
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:44:58+00:00 2026-05-25T11:44:58+00:00

I am using ajax with jQuery to make a request from a page on

  • 0

I am using ajax with jQuery to make a request from a page on my site. Now if the login failed (or the call failed for a different reason), I return an error message and put it in a label. But if the call succeeds, I want to navigate to another page. My issue is that if the call succeeds, I end up with the text of the new page in my label.

Here’s my Javascript:

 $.post("chklogin.php", { username: username, password: password }, function(data) {
        $('#msg').html(data);
 });

And here’s the PHP that it calls:

if(mysql_num_rows($result)==0) {
    $msg="<h3>Enter valid Username and Password.</h3>";
    echo $msg;
} else {
    $row=mysql_fetch_assoc($result);
    $_SESSION["userid"]=$row["pgmail"];
    header("location:user.php");
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T11:44:59+00:00Added an answer on May 25, 2026 at 11:44 am

    Well this issue could have been clearer, and I would encourage you to check your spelling and code before you post again.

    The issue is that you haven’t sent the page to redirect, you have sent the page being called to redirect.

    To fix this issue:

    Firstly, get rid of the header redirect on your PHP code and replace with:

    echo 'SUCCESS';
    

    Secondly, change your AJAX code to the following:

     $.post("chklogin.php", { username: username, password: password }, function(data) {
          if(data=='SUCCESS'){
             window.location.href = "user.php";
          }else{
             $('#msg').html(data);
          }
     });
    

    This will make the page redirect, not the page called by AJAX.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using jQuery to make an AJAX request to a remote endpoint. That
I make an AJAX request like so using JQuery: $.ajax({ type: GET, url: getvideo.php,
I am using the $.ajax function in jquery to make a call to an
I'm using jQuery to make an Ajax call using an Http Post in ASP.NET
I am using jQuery to make an AJAX call to a ruby method in
I'm using JQuery to make an Ajax call. I used a sniffer to catch
I am using this code from http://www.joe-stevens.com/2010/01/04/using-jquery-to-make-ajax-calls-to-an-asmx-web-service-using-asp-net/ function callWebService(address) { var result; $(#result).addClass(loading); $.ajax({
I'm making a request to a JSON page using jQuery's $.getJSON method, and from
I want to make an ajax call from jQuery to my server. Basically, I
im using jquery to make ajax requests. is it possible to detect if the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.