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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:20:49+00:00 2026-06-13T08:20:49+00:00

New to using this Jquery AJAX method. So i’m making an AJAX call with

  • 0

New to using this Jquery AJAX method. So i’m making an AJAX call with Jquery, In my PHP script i’m checking a condition to be true from my Database, before I pass in my datastring and bind the variables, then execute that query. Both the script and Database insert work correctly.

My question is, how can I get it to display the error message in my AJAX call on return from my PHP script?

JS


$.ajax({
type: "POST",
url: 'submit_form.php',
data: dataString,
error: function() { alert('Error'); },
success: function() { alert('Success'); }
});

SUBMIT_FORM.PHP

if ( count of rows in db < x  )
 {

return false;
exit();

}

if this condition is true I want to stop execution of my script and execute
the error condition in my AJAX function.


elseif ($stmt = $mysqli->prepare("INSERT INTO blah (stuff, morestuff) values (?, ?)")) {

 /* Bind our params */
  $stmt->bind_param("ss", $param1, $param1);

        /* Set our params */
$param1= $_POST["name"];
$param2= $_POST["email"];


/* Execute the prepared Statement */
$stmt->execute();
/* Close the statement */
$stmt->close(); 
}

if the first condition is false then I want to return the success function in my ajax call which it is currently doing.

  • 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-13T08:20:50+00:00Added an answer on June 13, 2026 at 8:20 am

    To invoke the error handler of your $.ajax, you can write the following code in PHP (for FastCGI):

    header('Status: 404 Not found');
    exit;
    

    Alternatively, use header('HTTP/1.0 404 Not Found') if you’re not using FastCGI.

    Personally I wouldn’t use this approach, because it blurs the line between web server errors and application errors.

    You’re better off with an error mechanism like:

    echo json_encode(array('error' => array(
        'message' => 'Error message',
        'code' => 123,
    )));
    exit;
    

    Inside your success handler:

    if (data.error) {
        alert(data.error.message);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using jquery ajax($.ajax) method to get a json object from c# webmethod.This
I am using a jQuery Ajax control from this site http://abeautifulsite.net/2008/03/jquery-file-tree/ I have it
I have a web method, which is called from jquery's ajax method, like this:
I am using JQUERY ajax to call an MVC method: JQUERY: $.ajax({ type: POST,
Hei guys i have this JQuery Ajax call from my view and it looks
Hello i'm using map() jquery to create a new object array DEMO but this
I'm new to jQuery. This would be no problem for me using XPath expressions,
I'm creating new Site Definitions using this method: http://weblogs.asp.net/paulballard/archive/2007/04/09/creating-a-custom-sharepoint-2007-portal-site-definition-using-the-portalprovisioningprovider-class.aspx and when they get created,
I'm currently using jquery ajax to call a pagemethod (which works great); $.ajax({ type:
I am having an issue when using the jQuery $.getJSON ajax call, though the

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.