java jquery ajax 应用

来源:互联网 发布:网络春晚冠名招商 编辑:程序博客网 时间:2024/04/28 18:18
//jquery ajax        function removelimit(str)        {            if(confirm("您确定要解除此账号吗?")){            $.ajax({                type:"post",//请求方式                url:"user.do?method=removeLandLimit",//发送请求地址                data:{//发送给数据库的数据                    username:str                },                //请求成功后的回调函数有两个参数                success:function(data,textStatus){                    alert("解除成功!");                }            });            }        }


        



以上是jquery ajax

下面是ajax ,代码比较多,不是很方便

<script type="text/javascript">            //删除                function removelimit(str)                {                if(confirm("您确定要解除此账号吗?")){                try{                  xmlHttp=new XMLHttpRequest();                     }catch(trymicrosoft){                  try{                    xmlHttp=new ActiveXObject(Msxml2.XMLHTTP);                  }catch(othermicrosoft){                    try{                        xmlHttp=new ActiveXObject(Microsoft.XMLHTTP);                        }catch(failed){                          xmlHttp=false;                        }                      }                   }                                                      if (xmlHttp==null)                  {                  alert ("Your browser does not support AJAX!");                  return;                  }                                var url="user.do?method=removeLandLimit";                xmlHttp.open("POST",url);                xmlHttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");                xmlHttp.send("username="+str);                //这样才不会报"完成该操作所需的数据还不可使用"错                xmlHttp.onreadystatechange=stateChangedcode;                return false;                }                }                function stateChangedcode()                {                 if(xmlHttp.readyState==4){                     if(xmlHttp.status==200){                         //alert(xmlHttp.responseText);                          //如果存在                          alert("解除成功");                                               }else if(xmlHttp.status==404){                           alert("请求的url不存在");                           //如果不存在                     }else                       alert("xmlHttp status is:"+xmlHttp.status);//状态码为200                       }                                          }    </script>      






0 0
原创粉丝点击