zoukankan      html  css  js  c++  java
  • jquery(ajax)与js(ajax)的比较

    原始js:

     1 function update_mess(){
     2     var account_name = $("#account").val();
     3                     var xmlhttp;
     4                     if(window.XMLHttpRequest){
     5                         xmlhttp = new XMLHttpRequest;
     6                     }
     7                     else{
     8                         xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
     9                     }
    10                     xmlhttp.onreadystatechange = function(){
    11                         if(xmlhttp.readyState == 4 && xmlhttp.status == 200){
    12                             var json = eval("("+ xmlhttp.responseText +")");
    13                             if(json.returnedjson.infostatus == 'T'){
    14                                 alert(json.returnedjson.infomsg);
    15                                 location.reload();
    16                             }
    17                             else{
    18                                 alert(json.returnedjson.infomsg);
    19                             }
    20                         }
    21                     }
    22                     var str = "account_id=" + account_id;
    23                     xmlhttp.open("post", "/update_mess_action", true);
    24                     xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    25                     xmlhttp.send(str);
    26 }

    ajax提交方式比js原始的提交方式更为简介,具体如下:

     1 $.ajax({
     2         type:"post",
     3         url:"find_password_action?account_name="+ account_name + "&account_answer1=" + account_answer1 + "&account_answer2=" + account_answer2,
     4         success:function(date){
     5             var json = eval("("+ date +")");
     6             if(json.returnedjson.infostatus == "T"){
     7                 //alert(json.returnedjson.infomsg);
     8                 $("#mymodal1").modal("toggle");
     9             }
    10             else{
    11                 alert(json.returnedjson.infomsg);
    12             }
    13         },
    14         error:function (date){
    15             alert("找回密码失败!");
    16         },
    17     });

    两种差不多,但是jquery的ajax更加灵活,对于post没有那么多的限制。

    努力吧,为了媳妇儿,为了家。。。
  • 相关阅读:
    数据库外键约束
    mysql查询数据
    操作mysql操作数据库
    自定义标签
    jstl标签
    getattibute 与 getparameter区别
    2017.3.2
    java中静态,抽象,接口,继承总结
    关于使用css伪类实现小图标
    动态生成的dom元素绑定事件
  • 原文地址:https://www.cnblogs.com/jlj9520/p/4912550.html
Copyright © 2011-2022 走看看