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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T23:02:53+00:00 2026-06-03T23:02:53+00:00

Im using ajax .POST to run php script that suppose to return true/false. Im

  • 0

Im using ajax .POST to run php script that suppose to return true/false. Im returning true/false using “echo” in my script. But after i get the result back to JS i compare the received text in an IF statement that never works! here is my code

 $.ajax({ url: 'admin_checkuser.php',
     data: {action: window.myId},
     type: 'post',
     success: function(output) {

if (output == "true"){

and here is the php script that being called

include_once('class.MySQL.php');

$userid = $_POST['action'];

$oMySQL = new MySQL();
$query = "Select * FROM videotable WHERE uid = '$userid'";
$oMySQL->ExecuteSQL($query);
$bb = $oMySQL->iRecords;
$aa = $oMySQL->aResult;


if ($bb == 0){
    $query = "INSERT INTO videotable VALUES ('','$userid','true')";
    $oMySQL->ExecuteSQL($query);
    echo 'true';
    exit();
}else{
    $sharing = mysql_result($aa,0,"share");
    echo $sharing;
    exit();
}

I made sure that i receive true\false by doing “alert(output)” and it always displays true\false so i really dont understand why my IF statement fails even when alert(output) shows true

Thanks in advance!

  • 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-03T23:02:55+00:00Added an answer on June 3, 2026 at 11:02 pm

    Trying to parse the type of an ajax response tends to be super unreliable, in my experience.

    For that reason, I (now) make darn sure that whenever I write a server side function that is meant for returning ajax data, I keep it perfectly in line with my own set response “standard”, and then set my response type in the ajax method to JSON.

    Doing so makes handling errors much more predictable.

    An example of a standardized response would be:

    $ajaxResponse = array(
      'data' => $someData,
      'result' => true,
      'message' => 'your yadayada was succesful',
      'timestamp' => time()
    );
    print json_encode($ajaxResponse);
    

    and in ajax, your response would be like:

    success: function( response ) {
       if(response.result) {
          alert(response.message);
       }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using Codeigniter, I am trying to get a php script to run after a
I am using jQuery to do an AJAX POST, but get a CSRF error.
I'm trying to POST a http request using ajax, but getting a response from
I am posting to the server using jquery ajax using $.post. After server returns
I have a form that needs to run a php script once the submit
I'm making an ajax call using jQuery as below. $.ajax({ type: POST, url: proc.php,
How to pass multiple checkboxes using jQuery ajax post this is the ajax function
When applying the MVP pattern to ASP.NET applications, where does using AJAX to post
I'm submitting a form using an ajax request (POST method), and checking the HTTP
How can we emulate the timeout of $.ajax using $.post ?

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.