XMLHttpRequest 不是函数 [英] XMLHttpRequest is not a function

查看:56
本文介绍了XMLHttpRequest 不是函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 XMLHttpRequest 编写一些客户端 JavaScript:

I'm trying to write some client-side JavaScript using XMLHttpRequest:

$('#someId').on('input', function() {
  var req = XMLHttpRequest();
  // …
});

但我收到以下错误:

XMLHttpRequest 不是函数.(在'XMLHttpRequest()'中,'XMLHttpRequest'是XMLHttpRequestConstructor的一个实例)

XMLHttpRequest is not a function. (In 'XMLHttpRequest()', 'XMLHttpRequest' is an instance of XMLHttpRequestConstructor)

如何解决这个问题?

推荐答案

missed new, must be:

missed new, must be:

$('#someId').on('input', function() {
  var req = new XMLHttpRequest();
  // …
});

您可以在此处阅读有关 XHRHttpRequest 的更多信息 -
https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest

you can read more about XHRHttpRequest here -
https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest

以及如何在此处使用它 -
https://developer.mozilla.org/ru/docs/XMLHttpRequest
(目前只有这个页面翻译存在,但谷歌翻译可以提供很多帮助:) )

and how to work with it here -
https://developer.mozilla.org/ru/docs/XMLHttpRequest
(only this page translation exists yet, but google translate can help a lot :) )

附言如果您使用的是 jQuery - 最好使用 $.ajax() 正如@synthet1c 所说的那样.

p.s. If you are using jQuery - better to use $.ajax() as @synthet1c said.

在此处阅读更多相关信息 - http://api.jquery.com/jquery.ajax/

Read more about it here - http://api.jquery.com/jquery.ajax/

这篇关于XMLHttpRequest 不是函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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