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 9241667
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T08:24:44+00:00 2026-06-18T08:24:44+00:00

Somehow I have confused myself. Somehow I got it in my head that when

  • 0

Somehow I have confused myself.

Somehow I got it in my head that when hitting PHP with AJAX (like $.post), you had to echo back a “true” or “false” instead of returning true/false. I see now that is not the case, but can someone break it down for me?

Is it that there is a problem testing a boolean? Like here

... 
$.post('ajax/doThing',{data: data},
    function(response) {
        if(response) {
            doThis();
        }else{
            doThat();
        }

That is the problem case, correct? Here I cannot return true/false, instead I must echo back a string and test the string, yes?

if(response === "true")

But I have seen boolean true/falses returned to ajax functions. What is the use of this, if you cannot test a boolean on the AJAX side? And why can’t ajax test a boolean?

Or am I still confused?

EDIT

Just wanted to thank everyone for their good answers on this. I am now +2 smrter.

  • 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-06-18T08:24:45+00:00Added an answer on June 18, 2026 at 8:24 am

    You might also look at returning HTTP error codes rather than returning a “success” response (HTTP status code 200) when the request wasn’t really successful, and then use an error callback to handle unsuccessful requests.

    But if you want to keep using status code 200 (and a lot of people do that):

    The data transferred between the client and the server is always text. The trick is to make sure that the client and server agree on how the client should deserialize the text (transform it upon receipt). Typically you might return one of four things:

    1. HTML (if it’s going to populate page elements)

    2. JSON (if you want a lightweight, fast way to send data to the client)

    3. XML (if you want a heavier-weight, fast way to send data to the client)

    4. Plain text (for whatever you want, really)

    What the client does will depend on what Content-Type header you use in your PHP page.

    My guess is that you’re using any of several content types that end up passing on the data as a string to your callback. The string "true" is truthy, but so is the string "false" (only blank strings are falsey).

    Long story short: I’d probably use this in my PHP:

    header('Content-Type', 'application/json');
    

    …and the return this text from it:

    {"success": true}
    

    or

    {"success": false}
    

    …and then in your success handler:

    if (response.success) {
        // It was true
    }
    else {
        // It was false
    }
    

    Alternately, you can return a Content-Type of text/plain and use

    if (response === "true") {
        // It was true
    }
    else {
        // It was false
    }
    

    …but that’s kind of hand-deserializing where you could get the infrastructure to do it for you.

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

Sidebar

Related Questions

I have a static method in my code that I would like somehow to
I'm somehow confused: I have a list of commands like this: var commands =
I somehow have the feeling that modern systems, including runtime libraries, this exception handler
The problem that I have is somehow very specific. I have to implement a
I am somehow aware of returning by reference by this got me confused. I
http://www.kidzoneapp.com/uses.html In this app, they somehow have an ability to protect users home button
I have somehow managed to break my infopath form :( When I try to
I have somehow managed to get a really screwed up Eclipse project. I have
i know this is basic but somehow i have been stuck here for some
I am using latest Pyramid to build a web app. Somehow we have started

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.