jQuery $ .ajax()功能-访问XMLHttpRequest对象 [英] jQuery $.ajax() functionality - Accessing the XMLHttpRequest object

查看:110
本文介绍了jQuery $ .ajax()功能-访问XMLHttpRequest对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以从$.ajax()函数的成功回调中访问XMLHttpRequest对象?具体来说,我需要访问IE中的XMLHttpRequest.responseBody.根据文档,返回的jqXHR对象不会公开.responseBody属性.

Is it possible to access the XMLHttpRequest object from the success callback of the $.ajax() function? Specifically I need access to XMLHttpRequest.responseBody in IE. Per the documentation the returned jqXHR object does not expose the .responseBody property.

这似乎是一个较小的站点,在处理二进制数据时会产生巨大的影响.如果.responseBody属性或基础XMLHttpRequest对象不可访问,我将不得不跳过jQuery for ajax,并将其编码为 shudder (纯JavaScript).

This seems to be a minor oversite that has a huge impact when dealing with binary data. If the .responseBody property or the underlying XMLHttpRequest object is not accessible I'll have to skip jQuery for ajax and code it in, shudder, pure javascript.

我实际上是在寻找responceBody变量,而不是可以从$.ajax()

I am infact looking for the responceBody variable, not the responceText variable that is readily accessible from within $.ajax()

推荐答案

您也可以使用beforeSend回调:

You can use beforeSend callback too:

$.ajax({
    beforeSend: function(jqXHR, settings){
        // Here you are the XHR object
        console.log(settings.xhr());
    }
});

这篇关于jQuery $ .ajax()功能-访问XMLHttpRequest对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆