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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T03:44:01+00:00 2026-06-01T03:44:01+00:00

GET_DATA() GET_DATA() contains this: var xhr; … function get_data( phrase ) { xhr =

  • 0

GET_DATA()

GET_DATA() contains this:

    var xhr;
    ...
    function get_data( phrase ) {
        xhr = function get_data( phrase ) {
        $.ajax({
            type: 'POST',
            url: 'http://intranet/webservice.asmx/GetData',
            data: '{phrase: "' + phrase + '"}',
            contentType: 'application/json; charset=utf-8',
            dataType: 'json',
            success: function( results ) {
                $("#div1").empty();

                if( results.d[0] ) {
                    $.each( results.d, function( index, data ) {
                        $("#div1").append( data.Group + ':' + data.Count + '<br />' );
                    });
                } else {
                    alert( "results.d does not exist..." );
                }
            },
            error: function(xhr, status, error) {
                $('#spanLoading').empty();

                 var err = eval("(" + xhr.responseText + ")");
                 alert(err.Message) ;
            }
        });
    }

    function get_default() {
        $('#div1').empty().append("default stuff goes here");
    }

UPDATE 2 CODE

I’ve also tried this, which doesn’t work either, no error messages, just returns the results of when the textbox had 2 characters when it finishes processing even if I delete everything before the process has finished:

$('#TextBox1').keyup( function() {
    if(xhr && xhr.readystate != 4){
        xhr.abort();
    }

    if ($("#TextBox1").val().length >= 2) {
        get_data( $("#TextBox1").val() );
    } else {
        get_default();
    }
});

UPDATE 1 CODE:

$('#TextBox1').keyup( function() {
    if ($("#TextBox1").val().length >= 2) {
        get_data( $("#TextBox1").val() );
    } else {
        if(xhr)
        {
            xhr.abort();
        }

        get_default();
    }
});

ORIGINAL QUESTION:

I have the following code:

$('#TextBox1').keyup( function() {
    if ($("#TextBox1").val().length >= 2) {
        get_data( $("#TextBox1").val() );
    } else {
        get_default();
    }
});

This has a slight glitch where if I type something really fast and then I delete it equaly fast, I see the data from get_default() flash on the screen, then it gets replaced by a previous ajax request where the value in the textbox was 2 which had not finished processing.

So basically, what I think is happening is that when the textbox has 2 characters in it, the ajax request starts which takes a second or 2. While this is happening, if I delete the 2 characters, I see the get_default() being successful, but it seems to replace it with the ajax data when the ajax data finishes.

How do I stop this from happening?

  • 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-01T03:44:02+00:00Added an answer on June 1, 2026 at 3:44 am

    Thank you for posting get_data.

    The reason why your AJAX call is not getting aborted is that xhr is not defined in the appropriate (window) scope; therefor, xhr.abort() doesn’t do anything (and quite probably throws an error if you take a look at your console).

    Please try the following:

    var xhr = false;
    
    function get_data( phrase ) {
        xhr = $.ajax({ /* ... etc */
    }
    

    The rest should work as is.

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

Sidebar

Related Questions

var data = $(#list2 li).map(function () { return $(this).children().html(); }).get(); the data variable contains
This post contains a lot of code, but I would really appreciate it if
i have this code // jquery $(document).ready(function() { $('#update_point').live(change, function() { var point_val =
My HTML which is at this url '/main/' contains the following link: <a href=/main/
I get data from server: store = new dojox.data.QueryReadStore({url:http://url_with_data}); ... myGrid = new dojox.grid.DataGrid({id:myGrid2,selectionMode:none,style:height:
I have next code block: $.post('page.php', function(data) { //data - full page info });
This url with right api-key https://www.googleapis.com/language/translate/v2?key=XXXXXXX&target=ru&source=en&q=hello contains: { data: { translations: [ { translatedText:
I have a backbone model called Member - this contains membership data such as
this is my escenary, I Have a class called Plantilla that contains severals propertyes
I have a store which is defined something like this: var AdditionalGridData = new

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.