Ajax使用
Javascript Ajax
- myurl="/Shop/GoodsSer?status=sendToCart&gid=1";
- getResult(myurl);
- var xmlhttp;
- function getResult(url){
- //创建XMLHttpRequest对象
- if(window.XMLHttpRequest){
- xmlhttp=newXMLHttpRequest();
- }
- else{
- xmlhttp=newActiveXObject("Microsoft.XMLHTTP");
- }
- if(xmlhttp){
- //打开url请求
- xmlhttp.open("GET",url,true);
- xmlhttp.setRequestHeader("Content-Type","text/html;charset=UTF-8");
- //请求被发送到服务器时,执行响应任务
- xmlhttp.onreadystatechange = complete;
- //发送
- xmlhttp.send(null);
- }
- }
- function complete(){
- //表示请求过程 0->4
- if(xmlhttp.readyState==4){
- //请求结果状态
- if(xmlhttp.status==200){
- var info=xmlhttp.responseText;
- }
- }
- }
Jquery Ajax
- $.ajax({
- type :"post/get",
- async :false/true,
- url :"*.do",
- data :{data1:$("").val(),data2:$("").val()},
- dataType :"text/xml/json",
- success :function(result){
- handler...
- }
- });
- $.post("login.do",{
- data1 : $('').val(),
- data2 : $('').val()
- },function(data){
- handler...
- },"json").error(function(){...};
- $.post("login.do", $("#form").serialize(),function(data){
- handler...
- },"json").error(function(){...};
动态加载js
- jQuery.getScript("static/library/plugins/city-select/jquery.cityselect.js",
- function(data, status, jqxhr){
- $("#city").citySelect({
- prov:"1", city:"1", dist:"1"
- });
- })
- });
/******************************************************************/
例子
- <script type="text/javascript">
- function send(){
- $("#login").animate({opacity:0.5},1000,function(){
- var uname = $("#uname").val();
- var pwd = $("#pwd").val();
- var _url ="/Chat/Login";
- $.ajax({url:_url, type:"get", dataType:"html", data:{action:'login',uname:uname,pwd:pwd},
- beforeSend:function(){
- $('#resDv').text("正在登录......");
- $('#resDv').fadeIn("slow");
- },
- error:function(){alert("登录失败!")}
- ,success:function(msg){
- $('#resDv').fadeOut("slow",function(){
- $("#login").animate({opacity:100},2000);
- $("#uname").val("");
- $("#pwd").val("");
- location.href="main/index.jsp";
- });
- }
- });
- })
- }
- </script>
 
                    
                
 
 
                
            
         浙公网安备 33010602011771号
浙公网安备 33010602011771号