在JSONHeader初始化XMLHttpRequest中解释DOM 11错误 [英] Explain DOM 11 error in the initialization of XMLHttpRequest with JSON -headers

查看:146
本文介绍了在JSONHeader初始化XMLHttpRequest中解释DOM 11错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到这个错误作为这个更大的谜题的一部分此处

I am getting this error as part of this larger puzzle here.

var xhr = new XMLHttpRequest();
xhr.setRequestHeader( 'Content-Type', 'application/json' );

//Error: INVALID_STATE_ERR: DOM Exception 11

进一步研究



  1. O'Reilly的书Javascript第6版定义指南在第491页的第18章脚本化HTTP中讨论了XMLHttpRequest,
    请注意,它不仅仅是关于HTTP或XML(历史遗迹)。

  1. O'Reilly's book "Definite Guide to Javascript 6th Edition" on page 491 in chapter 18 "Scripted HTTP" discussed XMLHttpRequest, please, note that it is not only about HTTP or XML (historical relics).

Mozilla的关于XMLHttpREquest的dev条目 here

Mozilla's dev entry about XMLHttpREquest here



推荐答案

您需要 open() XMLHttpRequest ,然后才能设置请求标头。在你调用 open()之后,将该行移动到

You need to open() the XMLHttpRequest before you can set request headers. Just move that line to after you call open():

var xhr = new XMLHttpRequest();
xhr.open( 'POST', 'example.php', true );
xhr.setRequestHeader( 'Content-Type', 'application/json' );

这篇关于在JSONHeader初始化XMLHttpRequest中解释DOM 11错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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