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

  • Home
  • SEARCH
  • 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 281281
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T05:11:23+00:00 2026-05-12T05:11:23+00:00

When i do an ajax request i go to a php script which does

  • 0

When i do an ajax request i go to a php script which does something for me.
Either it deletes an record from the db or it doesn’t.

If it goes ok. I want to deleted and update my html table. Else I want to show an error message or so.

But in my php I can’t do something like

return false;  
return true;

I need to echo my result or my message and then my jquery script will do something with it.

But how can I get jquery to do something depending on the outcome?

For example here:

jQuery.ajax({
            type: "POST",
            data: "id=" +id,
            url: "ajax_handler.php",
            success: function(msg){
                jQuery(tr).remove();
                jQuery("div.result").append("<p>"+msg+"</p>");
                jQuery("div.result").show();
                jQuery("div.result").fadeOut(5000);

            },
            error: function(msg){

            }

and the php code

$id = C_GPC::getPOSTvar("id");
$result ="";
if(isset($id) and ($id > 0)){
    $p = new C_product();
    $deleted = $p->deleteCategorie($id);
    if($deleted){
        $result = "ok";
    }else{
        $result = "not ok";
    }
}else{

    $result = "not ok";
}
echo $result;

I want to do A when ok and B when not ok. How should i deal with this?
});

  • 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-12T05:11:24+00:00Added an answer on May 12, 2026 at 5:11 am

    msg (the success result param) will return any output from the server/PHP script. So for your PHP script, if it doesn’t delete the record, then you could echo out an error message. In your Javascript code you can then check:

    if(msg == 'not ok')
    {
        alert('error occured');
    }
    
    if(msg == 'ok')
        alert('update the table');
    }
    

    You could set up something similar for your table/update.

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

Sidebar

Ask A Question

Stats

  • Questions 179k
  • Answers 179k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The way you describe how you are adding the items… May 12, 2026 at 3:46 pm
  • Editorial Team
    Editorial Team added an answer I would take a different approach. How about first introducing… May 12, 2026 at 3:46 pm
  • Editorial Team
    Editorial Team added an answer Both of those selectors work for me to select the… May 12, 2026 at 3:46 pm

Related Questions

I am sending an AJAX request to a Django view that can potentially take
I am working on a simple AJAX page. when the page loads, it should
Background I'm writing an asynchronous comment system for my website, after reading plenty of
I have the following Rails link generating code (I have removed potentially 'industry secret'

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.