【问题标题】:Convert Javascript XMLHttpRequest to jQuery将 Javascript XMLHttpRequest 转换为 jQuery
【发布时间】:2011-05-21 18:24:35
【问题描述】:

这段代码可以转换成jQuery代码吗?例如,使用:jQuery.get()。虽然我认为没有responsetypearraybuffer

var request = new XMLHttpRequest();
request.open("GET", url, true);
request.responseType = "arraybuffer";
request.onload = function() {
  // do stuff
}

request.send();

编辑

我正在尝试为 jQuery 制作 Chrome HTML5 Web Audio 插件。所以我尽量jQuerify。查看我尝试转换的内容@http://pieterhordijk.com/sandbox/html5-audio-api/webkit-audiocontext-interface/adding-a-basic-control

请注意不要点击音量高的播放按钮,因为您现在只能通过刷新页面来停止它:)

【问题讨论】:

  • 您的onload 应为onreadystatechangeresponseType 仅支持 FF >= 6。
  • @Marcel:FF 是什么?为什么我要将 onload 改为 onreadystatechange?
  • FF = 火狐; onload 不是 XMLHttpRequest 对象的属性。
  • 嗯,我正在研究的东西是实验性的(Chrome canary 版本)。所以你对浏览器的支持可能是对的。而且我需要使用 onload 而不是 onreadystatechange。
  • 啊哈,这让事情更清楚了。但是为什么要使用onload呢?

标签: javascript jquery ajax get


【解决方案1】:
$.get(url, function (data) {
    // do useful things with data
});

随意调整参数,见jQuery.get()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-18
    • 2017-07-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-31
    相关资源
    最近更新 更多