Jquery Ajax執行個體

來源:互聯網
上載者:User

標籤:style   blog   http   color   os   io   使用   strong   ar   

//1.$.ajax帶json資料的非同步請求var aj = $.ajax( {      url:‘productManager_reverseUpdate‘,// 跳轉到 action      data:{               selRollBack : selRollBack,               selOperatorsCode : selOperatorsCode,               PROVINCECODE : PROVINCECODE,               pass2 : pass2      },      type:‘post‘,      cache:false,      dataType:‘json‘,      success:function(data) {          if(data.msg =="true" ){              // view("修改成功!");              alert("修改成功!");              window.location.reload();          }else{              view(data.msg);          }       },       error : function() {            // view("異常!");            alert("異常!");       }  });//2.$.ajax序列化表格內容為字串的非同步請求function noTips(){      var formParam = $("#form1").serialize();//序列化表格內容為字串      $.ajax({          type:‘post‘,              url:‘Notice_noTipsNotice‘,          data:formParam,          cache:false,          dataType:‘json‘,          success:function(data){          }      });  }  //3.$.ajax拼接url的非同步請求var yz=$.ajax({       type:‘post‘,       url:‘validatePwd2_checkPwd2?password2=‘+password2,       data:{},       cache:false,       dataType:‘json‘,       success:function(data){            if( data.msg =="false" ) //伺服器返回false,就將validatePassword2的值改為pwd2Error,這是非同步,需要考慮返回時間            {                 textPassword2.html("<font color=‘red‘>業務密碼不正確!</font>");                 $("#validatePassword2").val("pwd2Error");                 checkPassword2 = false;                 return;             }        },        error:function(){}  }); //4.$.ajax拼接data的非同步請求$.ajax({       url:‘<%=request.getContextPath()%>/kc/kc_checkMerNameUnique.action‘,       type:‘post‘,       data:‘merName=‘+values,       async : false, //預設為true 非同步       error:function(){          alert(‘error‘);       },       success:function(data){          $("#"+divs).html(data);       }});

一、$.ajax的一般格式

$.ajax({

     type: ‘POST‘,

     url: url ,

    data: data ,

    success: success ,

    dataType: dataType

});

 

二、$.ajax的參數描述

參數 描述

url 必需。規定把請求發送到哪個 URL。
data 可選。映射或字串值。規定連同請求發送到伺服器的資料。
success(data, textStatus, jqXHR) 可選。請求成功時執行的回呼函數。
dataType

可選。規定預期的伺服器響應的資料類型。

預設執行智能判斷(xml、json、script 或 html)。

 

三、$.ajax需要注意的一些地方:

  1.data主要方式有三種,html拼接的,json數組,form表單經serialize()序列化的;通過dataType指定,不指定智能判斷。

  2.$.ajax只提交form以文本方式,如果非同步提交包含<file>上傳是傳過不過去,需要使用jquery.form.js的$.ajaxSubmit


 

參考連結:http://jun1986.iteye.com/blog/1399242

 

Jquery Ajax執行個體

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.