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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T15:21:53+00:00 2026-06-07T15:21:53+00:00

I am sending an email in jQuery and PHP, i need to tell the

  • 0

I am sending an email in jQuery and PHP, i need to tell the page to submit if the ajax was successful and don’t submit if not.
I have tried to place the return values in the success and error attributes, but that did not work, so i want to see if i could set the form to not send by returning false but if it was successful letting it submit the page for some server side work.

In the example below i have tried to set a variable and used a conditional to read it. I get an error message because the value does not seem to get passed globally, so when the conditional reads sendMe, it says it is undefined.

Is there a way to do this correctly?

$.ajax({
    type: "POST",
    url: "send.php",
    data: data,
    success: function(){
        var sendMe = 'true';
    },
    error: function(){
        alert('Error: Message could not be sent');
    }
});

if (sendMe == 'true'){
    //Submit the page...                    
}
else {
    return false;
}
  • 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-07T15:21:54+00:00Added an answer on June 7, 2026 at 3:21 pm

    just create a sendMe() function, and call that function from success:
    That should do the trick.

    The reason your code does not work is because the javascript is not waiting for the ajax call to come back, right after the ajax call it evaluates sendMe which at that point is still false.

    You could consider doing this call synchronously of course to prevent that, but I am not sure that is the right way to go. ( async : false is deprecated as of jQuery 1.8 )

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

Sidebar

Related Questions

I have a jquery function for sending email with ajax request; function sendMail(from,to,subject,message){ var
i have a simple Jquery code which is for sending $.ajax request and passing
I have code for sending email to clients. System.Net.Mail.SmtpClient Client = new System.Net.Mail.SmtpClient(); MailMessage
I built a basic form with ajax validation and page redirection with PHP and
Possible Duplicate: Sending Email in .NET Through Gmail I have so many problems with
I have this simple jQuery ajax post to a Pyramid webapp. Ajax call: $.ajax({
While sending email, I get the following error: The device is not ready at
I'm getting a weird result from a jQuery ajax request sending form details to
I am sending email using the following utility class, if receiver foo@foo.com is not
I have a php function which is called by a jquery function. This jquery

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.