复习XMLHttpRequest,记个小笔记

有时候xhr的post方式下,后台总是获取不了post过来的数据,这个其实跟页头有关。

var xhr = new XMLHttpRequest;
xhr.open('post', 'http://xiebiji.com', true);
xhr.onreadystatechange = function () {
	if (this.readyState != 4)
	return;
}
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');//少了这一句post形式就悲剧了
xhr.send('de=gh');

8 Responses to 复习XMLHttpRequest,记个小笔记 »

  1. 独自流浪 评论 2010-11-26 13:13

    刚才打开你的网站和这篇文章,都是先出现一堆http响应,要刷新才有内容出现
    1.1 200 OK
    Server: Apache/2.0.43
    Content-Type: text/html
    Expires: -1000
    Cache-Control: no-cache
    Connection: close
    Date: Fri, 26 Nov 2010 13:12:22 GMT
    Content-Length: 981

    var stat_path=’http://121.32.136.245:81/stat.aspx?p=1290748342|7435262|3074|0|0|0′;
    var cnt_path=”;
    window.setInterval(‘window.status=location.href’, 200);

    var content=’http://gd.ct10000.com/gz/zt/201003s/zeroyc/0yc_at1125.htm?p=1290748342|7435262|3074|0|0|0&param=ABioyajZGekprCmIWbjJPNzczIys/Ozb/OyczRmJvZj5CTlpyGlpvCzM/Iy9mMkIqNnJqKjZPCh5aanZaVltGckJLQwM7Nxs/Iy8fMy80=’;
    var old_url=’http://xiebiji.com/?1290748342′;
    var param=’420|320|9′;
    if(checkpop(stat_path))
    {try{OpenWin(content,stat_path,cnt_path,old_url);}catch(e){}}
    else{location.href = old_url;}

    后面一堆乱码

    回复

    joe 回复 十一月 27th, 2010 at 00:29

    谢谢提醒

    回复

  2. 好淘网 评论 2010-11-28 11:48

    学习了 又 嘿嘿

    回复

  3. 泰瑞斯凯孚轴承 评论 2010-12-01 15:36

    只对你说:博客真不错,css很好

    回复

  4. 祛痘产品排行榜10强 评论 2010-12-08 19:29

    呼呼 又学到了点

    回复

  5. weber 评论 2010-12-10 09:35

    xhr.setRequestHeader(‘Content-Type’, ‘application/x-www-form-urlencoded’);//少了这一句post形式就悲剧了
    因为服务器不认识那些类型,哈哈
    ‘application/x-www-form-urlencoded‘意思差不多就是让此数据被解码的方式就像它在请求url的方式一样,还有很多其它的“HTTP Content-Type”

    回复

  6. 男士如何祛痘 评论 2010-12-20 13:21

    又学到东西了,赫赫

    回复

  7. 复习XMLHttpRequest,记个小笔记 Pingback 2011-05-24 07:47

    [...] 与本文相关的日志2010-10-19 — 简单的js调试函数2010-10-14 — 最近几个关于js的笔记2010-05-27 — 多层div相互层叠激活方法(提升z-index)2010-02-01 — js中自定义mouseenter、mouseleave的写法2010-01-31 — 实际上js文件放最后是个好方案,但有更好的方案 View full post on 写笔记的小JOE页 [...]

Leave a Reply

Email address is not published

You should say a Chinese word to pass spam check. If you can not input Chinese, just copy 你好 and paste them into comment text box.