码迷,mamicode.com
首页 > Web开发 > 详细

AJAX

时间:2017-11-11 22:57:19      阅读:174      评论:0      收藏:0      [点我收藏+]

标签:ready   XML   str   ack   ==   code   nal   安全性   html   

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title></title>
    <script>
      window.onload=function(){
        let aBtn=document.getElementById(btn);
        aBtn.onclick=function(){
          let xhr=new XMLHttpRequest();
          xhr.open(get,data/2.txt,true);
          xhr.send();
          xhr.onreadystatechange=function(){
            if(xhr.readyState==4){
              if(xhr.status==200){
                alert(成功);
                let json=null;
                try {
                  json=JSON.parse(xhr.responseText);
                } catch (e) {
                  json=eval((+xhr.responseText+));
                } finally {
                  console.log(11);
                }
                console.log(json);
              }
            }
          }
        }
      }
    </script>
  </head>
  <body>
<input type="button" name="" value="提交" id="btn">
  </body>
</html>

 

1.接收响应数据:
xhr.responseText 文本数据
xhr.responseXML xml数据
2.eval——不安全
3.JSON
JSON.stringify {a: 12, b: 5} => "{\"a\": 12, \"b\": 5}"
JSON.parse "{\"a\": 12, \"b\": 5}" => {a: 12, b: 5}

JSON——不兼容
4.安全:
1.前台没有安全性;后台才有问题(sql注入)
2.xss——跨站脚本攻击

ajax不允许跨域

5.json标准格式:
1.key必须用引号包起来
2.双引号

{"a": 12, "name": ‘blue‘}

AJAX

标签:ready   XML   str   ack   ==   code   nal   安全性   html   

原文地址:http://www.cnblogs.com/chaofei/p/7820165.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!