3

I have a jquery.ajax object in which I want to substitute xhr. However executing the following code gives me an error:

TypeError: Property 'xhr' of object #<Object> is not a function

The relevant code is:

    var req = jQuery.ajaxSettings.xhr();
    req.upload.addEventListener('progress', calendar.check_progress, false);

    $.ajax({
        url: script_root + '_save_file/'+id+'/'+timestamp,
        type: 'POST',
        processData: false,
        contentType: false,
        data: fd,
        xhr: req,
        success: function(data){
            do_something();
        },
        error: function(data){
            console.log(data);
            do_something_else();
        }
    });
1
  • Ajax method has no function by name xhr: req .. this is messing up your request Commented Sep 11, 2012 at 16:50

1 Answer 1

2

xhr is used in other way. See documentation: http://api.jquery.com/jQuery.ajax/

xhr: Function

Default: ActiveXObject when available (IE), the XMLHttpRequest otherwise

Callback for creating the XMLHttpRequest object. Defaults to the ActiveXObject when available (IE), the XMLHttpRequest otherwise. Override to provide your own implementation for XMLHttpRequest or enhancements to the factory.

May be you're looking for something like

xhr: function() {
    var xhr = $.ajaxSettings.xhr();
    xhr.upload.addEventListener('progress', calendar.check_progress, false);
    return myXhr;
},
Sign up to request clarification or add additional context in comments.

1 Comment

Shouldn't it be var myXhr = $.ajaxSettings.xhr();? Seems to be a typo.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.