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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T08:03:51+00:00 2026-05-28T08:03:51+00:00

I have an AJAX request (using JQuery) that calls a PHP script which does

  • 0

I have an AJAX request (using JQuery) that calls a PHP script which does some database business. The request code is as follows:

$.ajax({
    url: "script.php",
    data: { value: value
        },
    type: 'post',
    success: function(output){
        alert(output);
    }
});

However, I wanted to see if there was a way to also (in addition to the unchanged output string) return a status. It can be as simple as an integer. The point is I want to disable a button (with Javascript) if the PHP script for any reason fails to connect to mySQL, but I still want the PHP scripts output exactly as it would be.

I tried the error option:

...
success: function(output){
        alert(output);
    },
error: function(output){
        // do something
    }

but I do not know how to make PHP display an error and continue on the rest of the script. Again, I don’t want to tamper at all with the output string.

In pseudo-code, I’m looking for something like this:

$.ajax({
    url: "script.php",
    data: { value: value
        },
    type: 'post',
    success: function(output){
        if(output.status == 0){
            alert(output);
        }else{
            // do something else
        }
    }
});

Is anything of the sort possible? Thanks for any and all help!

  • 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-28T08:03:51+00:00Added an answer on May 28, 2026 at 8:03 am

    I usually return data from the server in JSON format. This way I can return as many different types of data as may be needed by the success function in javascript.

    basically in PHP you would do something like

    $response = new stdClass();
    $response->error = 'Could not connect to Mysql';
    $response->message = 'Some other text';
    echo json_encode($response);
    

    in JQuery, the ajax() method would automatically detect that the response is json and parse it into a javascript object, so you could access like this

    if (typeof response.error !== undefined) alert(response.error);
    

    for more on that look at dataType argument for the ajax() method in the jQuery documentation.

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

Sidebar

Related Questions

Is it possible that using jQuery, I cancel/abort an Ajax request that I have
I have written some jQuery ajax code where I am sending a request to
Using Jquery Ajax i have an entry script index.php This script lets the user
I have a spinner that displays when an ajax request is made using jquery:
I have a simple jquery/ajax request to the server which returns the structure and
I am using jQuery for my Ajax calls... I have x amount of Ajax
I've rewritten my family web site using JavaScript (JQuery) making Ajax calls to PHP
I make an AJAX request like so using JQuery: $.ajax({ type: GET, url: getvideo.php,
I have a problem with my JQuery, Ajax, and PHP code. I have a
Let's say, for example, that I have some buttons that calls AJAX requests when

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.