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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T12:19:52+00:00 2026-05-12T12:19:52+00:00

I have a jQuery dialog box that opens and then an AJAX call is

  • 0

I have a jQuery dialog box that opens and then an AJAX call is made. I would like to make it so that if the dialog box is closed or the cancel button is pressed the AJAX call is canceled and its callback function is not called. I can think of some ways to do it with a variable like so:

  function doStuff(){
    var doCallback = true;
    $('#dialog').dialog({
      title: 'Dialog Title',
      modal: true,
      buttons: {
        Cancel: function() {
          doCallback = false;
          doSomethingElse();
        }
      }
    });
    $.get('url/url/url', function(data){
      if(doCallback){
        doTheSuccessThing(data);
      }
    });
  }

But, somehow that feels dirty to me and it doesn’t actually stop the AJAX call from completing. Is there a built-in way to cancel an AJAX call in progress?

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

    Ok, so based off of the suggestion to use the XmlHttpRequest object returned by the $.get function I came up with this:

    function doStuff(){
        var ajaxRequest = $.ajax({
                            url : 'url/url/url',
                            type : "GET",
                            success : function(data){
                              ajaxRequest = null;
                              doSuccessStuff(data);
                            }
                          });
    
        $('#dialog').dialog({
          title: 'Stuff Dialog',
          bgiframe: true,
          modal: true,
          buttons: {
            Cancel: function() {
              if (ajaxRequest)
                ajaxRequest.abort();
              doCancelStuff();
            }
          }
        });
      }
    

    It seems to work and feels cleaner to me.

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

Sidebar

Related Questions

I have a jquery dialog box that opens by means of a link. I
I have the following Jquery that returns values from a dialog Box and fills
I have a jQuery UI Dialog box, that I'm creating. It starts out as
I have a jquery dialog box that is used to edit and update a
I have a dialog box in mvc that opens up first time but not
I have a dialog box that I open using jQuery 1.7.1. The html for
I have a jQuery UI Dialog Box that contains a jQuery UI Autocomplete input
I have an application that uses jQuery to open a dialog box with a
I have a page that, at the user's request, opens a dialog box and
I have jquery ui dialog box, and I want to resize it by 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.