ajax与后台交互

前端之家收集整理的这篇文章主要介绍了ajax与后台交互前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

向controller请求数据:

  1. $(document).ready(
  2.       function(){
  3.         jQuery.ajax( {
  4.           type : 'GET',
    		    async: false,
  5.           contentType : 'application/json',url : '/holiday/currentAnnualHolidayInfo?id=1',dataType : 'json',255)">data""outdata.records));//转换成字符串格式弹出
  6.             if (data && data.success == true) {
  7.               
  8.                  
  9.                 });
  10.               }
  11.             }
  12.           },error: function(XMLHttpRequest,textStatus,errorThrown) {
  13.             alert(XMLHttpRequest.status);
  14.             alert(XMLHttpRequest.readyState);
  15.             alert(textStatus);
  16.           },complete: function(XMLHttpRequest,textStatus) {
  17.             this; // 调用本次AJAX请求时传递的options参数
  18.           }
  19.         });
  20.       }
  21.   );

  1. 后台json格式提交数据:
  1. jQuery.ajax({
  2. type: 'POST',contentType: 'application/json',async: false,url: url,dataType: "json",data: JSON.stringify(postData),success: function (data) {
  3. alert("return2" + JSON.stringify(data));
  4. },error: function (XMLHttpRequest,errorThrown) {
  5. alert(XMLHttpRequest.status);
  6. alert(XMLHttpRequest.readyState);
  7. alert(textStatus);
  8. },complete: function (XMLHttpRequest,textStatus) {
  9. this; // 调用本次AJAX请求时传递的options参数 }
  10. });

  1.  
设置全局同步:

async默认是为TRUE的,

$.ajaxSetup({
async: false
});

猜你在找的Ajax相关文章