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

  • Home
  • SEARCH
  • 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 6240173
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T11:31:09+00:00 2026-05-24T11:31:09+00:00

I am returning a string form php and compare it with another string in

  • 0

I am returning a string form php and compare it with another string in jQuery. I am 100% certain that the strings do match (well, at least are of the same value…), but still my if-clause thinks otherwise.

This is the part of my php-script that sets the returning value:

if (!$result){
        echo "false";
        exit();
    }

This is my jQuery that performs the matching:

$.post("registeraccount.php",$(this).serialize(),function(msg){
        //alert the response from the server
        alert(msg + " = " + (msg == "false"));
        if(msg == "false"){
            $("#adminarea").html("Error");

        }else{
            $("#adminarea").html("Success");
        }

   });

No matter that the strings are equal or not equal, it’s always “Success” that is printed on the web page.

In the alert I get the following result “false = false”. Hence, (msg == “false”) is false.

How come the strings are not true when they are equal and how do I fix it?

  • 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-24T11:31:09+00:00Added an answer on May 24, 2026 at 11:31 am

    I suppose that the reason is that msg, your server output, is never exactly “false”, due to some line endings that are added or similar things in you PHP script (you could check if msg has the length you expect to verify this hypothesis). In this case, you could try using this:

     if (msg.match(/false/)) {
    

    which does a somewhat less strict comparison if you want, ensuring that the output contains the string “false” (at any position). If it works, I suggest that you use instead this comparison:

     if (msg.match(/^false$/)) {
    

    which guarantees that false be a whole line of your text.

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

Sidebar

Related Questions

I have a custom form that's returning the values to the main form but
I am having some issues returning data from on page, using jQuery, PHP and
I am returning a JSON string from PHP: <?php $results = array( result =>
I am creating an jquery ajax form which calls the method below public string
I am returning a string of either T or F from an NSDictionary key
Instead of returning a common string, is there a way to return classic objects?
I am returning a JSON object (as a String) through a servlet. The JSON
This morning I ran into an issue with returning back a text string as
I'm trying to use window.getSelection to get a string but it's returning an object.
Consider the following code where I am returning double& and a string& . It

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.