`

AJAX同步POST访问servlet时 refuse to set unsafe header 'Content-length '

 
阅读更多

XMLHttpRequest 对象用于和服务器交换数据。

向服务器发送请求

如需将请求发送到服务器,我们使用 XMLHttpRequest 对象的 open() 和 send() 方法:

xmlhttp.open("GET","test1.txt",true);
xmlhttp.send();
方法 描述
open(method,url,async)

规定请求的类型、URL 以及是否异步处理请求。

  • method:请求的类型;GET 或 POST
  • url:文件在服务器上的位置
  • async:true(异步)或 false(同步)
send(string)

将请求发送到服务器。

  • string:仅用于 POST 请求

GET 还是 POST?

与 POST 相比,GET 更简单也更快,并且在大部分情况下都能用。

然而,在以下情况中,请使用 POST 请求:

  • 无法使用缓存文件(更新服务器上的文件或数据库)
  • 向服务器发送大量数据(POST 没有数据量限制)
  • 发送包含未知字符的用户输入时,POST 比 GET 更稳定也更可靠

 

POST 请求

xmlhttp.open("POST","demo_post.asp",true);
xmlhttp.send();

 

GET 请求

xmlhttp.open("GET","demo_get.asp",true);
xmlhttp.send();

 

如果需要像 HTML 表单那样 POST 数据,请使用 setRequestHeader() 来添加 HTTP 头。然后在 send() 方法中规定您希望发送的数据:

xmlhttp.open("POST","ajax_test.asp",true);
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlhttp.send("fname=Bill&lname=Gates");

 

方法 描述
setRequestHeader(header,value)

向请求添加 HTTP 头。

  • header: 规定头的名称
  • value: 规定头的值
但使用post方法传数据时会报如下错误:
 原因是使用chrome浏览器:chrome是按照w3c标准来执行的,你可以看这里的原文描述,http://www.w3.org/TR/XMLHttpRequest/#...
Terminate these steps if header is a case-insensitive match for one of the following headers:

Accept-Charset
Accept-Encoding
Connection
Content-Length
Cookie
Cookie2
Content-Transfer-Encoding
Date
Expect
Host
Keep-Alive
Referer
TE
Trailer
Transfer-Encoding
Upgrade
User-Agent
Via
本人是通过chrom浏览器进行D3的绘图,所以只能取个折中的办法,采用get方法访问后台数据,效果如下:

 
  • 大小: 15.7 KB
  • 大小: 37.3 KB
分享到:
评论

相关推荐

    Refuse

    Refuse

    Refuse To Be Human-crx插件

    语言:English ...因为虽然网站所有者将向普通用户显示登录页面,但他们将向网络爬虫授予其完整档案的访问权限,以便在Yandex的搜索结果中显示该档案。 第1步::laptop:安装Web扩展程序第2步::satellite_antenn

    rufus-3.13p写盘工具.rar

    rufus-3.13p 2:管理员方式打开Rufus: ... en_windows_10_business_editions_version_20h2_updated_jan_2021_x64_dvd_533a330d 4:“镜像选项”选择“标准Windows安装”。 5:准备用M2固态盘装系统,分区类型选择“MBR...

    Android 使用记录访问权限(PACKAGE-USAGE-STATS)、UsageStatsManager

    Android 使用记录访问权限(PACKAGE_USAGE_STATS)、UsageStatsManagerAndroid 使用记录访问权限(PACKAGE_USAGE_STATS)、UsageStatsManagerAndroid 使用记录访问权限(PACKAGE_USAGE_STATS)、...

    refuse-,reject的用法区别参考.doc

    refuse-,reject的用法区别参考.doc

    ISO 24162-2022 energy consumption of refuse collection vehicles

    ISO 24162-2022-Test method for energy consumption of refuse collection vehicles.pdf

    edjpgcom|图片中插入一句话

    refuse to handle a non-jpeg file. If you use ThumbsPlus to manage your photos (highly recommended), you can add edjpgcom as an external program using the following steps: * Right-click on the tool ...

    Refuse_classification.ino

    Refuse_classification.ino

    Matlab 2014a 破解文件

    When you will be ascked to activate the program REFUSE to do so. If simplified setup does not work for you just execute folowing steps manually: (to save time try to execute STEP 7 ONLY ... and if it...

    refus-3.5 制作U盘启动工具

    快速制作iso系统镜像文件的U盘启动,简单,方便,方便用户进行系统的安装。

    Android代码-marketlauncher

    (which normally they refuse to do). Registers to handle urls in the 'marketlauncher:' scheme from the browser. Checks for URLs of the form 'marketlauncher://details?id=...' or 'marketlauncher://search...

    project-refuse-deleter-air:开源实用程序“ Kas Delete-kun”的开发存储库

    主要在发布和交付用于Web / RIA开发的文件时很有用。 您可以从以下链接下载“ Kasu Delete-kun”的AIR应用程序文件的最新版本。 由于它是AIR应用程序,因此可以在任何操作系统(Windows / macOS)上使用。 *需要...

    Research on Composition and Recycle Value of Aged Refuse at Shanghai Refuse Landfill

    老港生活垃圾填埋场垃圾组成和资源化价值研究,杨玉江,赵由才,在上海老港生活垃圾填埋场,对1991~2004年间填埋垃圾进行了小规模开采和手工分选,考察了填埋垃圾组成随填埋年份的变化规律。分选结

    ImagesBy360.zip

    In the face of ambiguity, refuse the temptation to guess. There should be one-- and preferably only one --obvious way to do it. Although that way may not be obvious at first unless you're Dutch. ...

    单元测试框架.txt

    In the face of ambiguity, refuse the temptation to guess. There should be one-- and preferably only one --obvious way to do it. Although that way may not be obvious at first unless you're Dutch. Now ...

    struts2 in action

    经典manning 原板书。...refuse. It’s been a pleasure working with Don, but mostly it’s just nice to be able to pick his brain about the details of Struts 2. That alone is worth the price of admission.

    怎样装双sata硬盘

    详细的双硬盘安装,包括硬件安装和软件安装。在关机状态,把数据线、电源线都插到硬盘,与主板相连。然后开机,插入光驱系统盘,格式化、分区,安装系统。ok

    最新完整版标准 ISO 24162-2022-Test method for energy consumption of

    最新完整版标准 ISO 24162-2022-Test method for energy consumption of refuse collection vehicles.pdf

    AVG 破解版

    The Licensor shall be entitled to refuse the type of subsequent performance chosen, if this is only possible at disproportionate expenses, and the other type of subsequent performance will be without...

Global site tag (gtag.js) - Google Analytics