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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:56:54+00:00 2026-05-23T12:56:54+00:00

I’m having a problem executing a certain bit of AJAX. Here is how I

  • 0

I’m having a problem executing a certain bit of AJAX. Here is how I want to happen:

I have a form where upon pressing a button I want to execute a small bit of Javascript (confirm the execution of the action), send an AJAX request, and then submit the form. I don’t care about the output of the AJAX request, but it needs to run before the form is submitted.

The button is defined as:

<input title="Delete" onclick="return check_delete('id');" 
type="submit" name="Delete" value="Delete">

The function check_delete is:

var sure = confirm('Are you sure you want to delete this?');
if (!sure) return false;

var del = confirm('Would you like to delete related content?');
if (window.XMLHttpRequest) {
    xmlhttp=new XMLHttpRequest();
} else {
    xmlhttp=new ActiveXObject('Microsoft.XMLHTTP');
}
var url = '/del_check.php&id='+id+'&del='+del;

xmlhttp.open('GET',url,true);
xmlhttp.send();
return true;

The function runs fine, except for the xmlhttp.send() part – the request does not show up in the web-server’s logs, and does not get executed. After playing with it a bit, I found that if I change the last line in the function to return false instead of true, my AJAX starts working, however, because of the false return value, the form does not get submitted.

What am I missing?

  • 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-23T12:56:55+00:00Added an answer on May 23, 2026 at 12:56 pm

    This line:

    xmlhttp.open('GET',url,true);
    

    means you’re issuing an asynchronous request (MSDN, W3C). The request is initiated by your code, but your code doesn’t block waiting for it to complete (which is normally a Good Thingtm).

    However, when you submit a form, the page is torn down and replaced with the result of the form submission. Any outstanding or queued ajax requests will be aborted or never even started.

    You could make the request synchronous (blocking) by changing that true to a false, but then you’ll lock up the page (at best) or the browser (at worst) until that request completes, which isn’t ideal.

    Alternatives are to avoid doing the ajax request entirely, or to cancel the form submission, wait for the ajax response (even though you don’t care about it), and then submit the form programmatically (via HTMLFormElement#submit — e.g., calling submit on the form‘s DOM element). If you do that second one, note that the button you clicked won’t be included in the form data unless you manually insert it, since the form is no longer being submitted by that button.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I have a French site that I want to parse, but am running into
I have a text area in my form which accepts all possible characters from
I have just tried to save a simple *.rtf file with some websites and
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I want use html5's new tag to play a wav file (currently only supported
I am currently running into a problem where an element is coming back from
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

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.