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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T18:45:36+00:00 2026-05-23T18:45:36+00:00

I’m making an AJAX script based on jQuery.ajax() and have come to a point

  • 0

I’m making an AJAX script based on jQuery.ajax() and have come to a point where I should somehow check if the link I’m trying to load is a html page or something different like a swf, image or zip. So I need to somehow check the content-type header and decide if I should get the content also (if it’s html) or throw the ajax call away and do a window.location = theUrl. What I don’t want is to get the entire file just to find out it’s a 100MB zip file.

Is there a way to ‘pause’ (or abort) the request while its still going and read just the headers ? HEAD call is not an option because this way I would have to make 2 requests to the server every time.

Maybe some sort of hack with setTimeout and low-level xhr functions?

Thanks in advance! 🙂

EDIT: Tried to get the headers from xhr in setTimeout before the request finished but it doesn’t seem to populate it until all of the data has been fetched.

EDIT 2: I hacked my way around the jquery’s thing that binds itself to onreadystatechange:

var xhrr = new window.XMLHttpRequest();
$.ajaxSetup({
    xhr: function() { return xhrr }
});

...
$.ajax(....);

var theirfunc = xhrr.onreadystatechange;
xhrr.onreadystatechange = function() {
    console.log('xhr state: ', xhrr.readyState);
    theirfunc();
};

So this gave me states 1, 2, 3, 4 in order and I could get the content-type and abort successfully. I’m still investigating why it won’t work when jquery itself creates the XMLHttpRequest object. If I skip the ajaxSetup part and get var xhrr = $.ajax(...) then bind the same way it won’t work. So how is my xhr any different than jquery’s? I see they do it like this:

function createStandardXHR() {
    try {
        return new window.XMLHttpRequest();
    } catch( e ) {}
}

So it shouldn’t make a difference?

EDIT 3: Found it! jquery 1.6 returns a fake xhr object with just a small number of the properties and onreadystatechange is NOT one of them.

  • 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-23T18:45:36+00:00Added an answer on May 23, 2026 at 6:45 pm

    You might have to hack jQuery. I don’t know how to do this in detail, but…

    jQuery uses XMLHttpRequest() to load data. If you look here (mind where the page will be scrolled)

    http://en.wikipedia.org/wiki/XMLHttpRequest#The_onreadystatechange_event_listener

    you will find that it’s somehow possible to attach a listener that listens for the headers to be loaded. The data would then continue to load, but using the abort() function you can abort that.
    If you look in the jQuery source code:

    http://www.google.com/codesearch#LARMQtWqu54/trunk/spec/support/jquery-1.4.4.js&q=xmlhttprequest%20package:jQuery&type=cs

    and search for xhr.send (1 match) and window.XMLHttpRequest (2 matches) , you will see that those options are not used by jQuery natively (note that xhr is an XMLHttpRequest). However, in the first match of window.XMLHttpRequest it is indicated in the comments that you can override this object. However, in the second match the comment is not there, so I’m not sure if this would be overridden as well (hence you might need to hack to have it work in all browsers). You would need to extend XMLHttpRequest and modify the constructor and/or send method to call its parent’s. Pass that object to jQuery in the way the comments refer to.

    I hope you know how listeners work and how object-orientation works in javascript.

    • 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 have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am trying to loop through a bunch of documents I have to put
I have just tried to save a simple *.rtf file with some websites and
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
this is what i have right now Drawing an RSS feed into the php,
I am reading a book about Javascript and jQuery and using one of the
I have this code to decode numeric html entities to the UTF8 equivalent character.

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.