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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T15:52:58+00:00 2026-06-16T15:52:58+00:00

here I have jQuery ajax calling a .php file that SOMETIMES executes let’s say

  • 0

here I have jQuery ajax calling a .php file that SOMETIMES executes let’s say the following

echo "hello"

Here it is:

    $.ajax({
        type: "POST",
        url: myurl.php
        data: data_string,
        timeout: 6000,
        success: function () {

        }
    });

I would like to know: is it possible to make the ajax return ERROR and not SUCCESS when something like the previous echo is executed in the PHP file? I mean, checking inside this $.ajax if the php file is executed as I would or not.

EXPLAINING BETTER:
I get error when the request could not be completed and success when it could. But I would like to get like a return value from this PHP file. If it returns 1, I wanna do something. If it returns 2, instead, I wanna do something else. Hope I explained it better..

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-16T15:52:59+00:00Added an answer on June 16, 2026 at 3:52 pm

    I recommend using json_encode() within your PHP file. For example:

    echo json_encode(array('success' => 'do_foo'));
    exit();
    

    Then you can add a conditional within the success callback:

    $.ajax({
      type: "POST",
      url: myurl.php
      data: data_string,
      dataType: "JSON", //tell jQuery to expect JSON encoded response
      timeout: 6000,
      success: function (response) {
        if (response.success === 'hello'){
          console.log(response);
        } else {
          console.log('else');
        }
      }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I just have started writing AJAX functions using jquery. Here i am calling myfunction()
Here's the story... I have a jQuery function that does something, this function is
I have this following jquery text fly-in animation.Here is my code before I explain
I have a page going here that uses jQuery: http://treethink.com/services What I am trying
In my PHP/jQuery application, I have a javascript file, in which I can call
this problem is driving me crazy... I'm calling a PHP file through Ajax and
I've got a WebMethod that I'm calling from jQuery AJAX. No matter what I
So I have ajax file upload partial (using Jquery Form plugin), it's working perfectly,
I have an ajax call to one php script via jquery but it takes
I have some jQuery with an Ajax call that looks like this: $.ajax({ type:

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.