Jquery中ajax基本语法

一.$.ajax的基本使用结构
var response = $.ajax({
        type: "POST",
        url: "/index.php?m=content&c=index&a=getList",
        data: {
            "page" : currentPage,
            "pTime":new Date().getTime()
        },
        dataType: "json",
        beforeSend:function(){
            //发送时的代码提示
        },
        success: function(data){
            //成功时的代码提示
        },
        complete:function(){
            //完成时的代码提示
        },
        error: function (msg){
            //报错时的代码提示
        },
        async: true
    });
二.$.post的基本使用结构
var data = {
      'page':page,
      'pagesize':pagesize,
      'type': type
    }
    $.post(
        '/index.php?m=content&c=index&a=index',
        data,
        function(data){
            console.log(data);
        },
        'json'
    );
三.$.ajax的onready事件
$(function(){
     //加载事件
});
$(document).ready(function(){
  //加载事件
});
四.juery的on方法绑定动态元素的点击事事件
/**
 * 事件绑定处理
 */
jQuery(document).on("click","[rel='zanLink']",function(event){
    //判断是否登陆
    if(!jQuery.cookie("58haha_t")){
      window.location.href = passport_login;
      return false;
    }
    //代码处理
});

猜你喜欢

转载自www.cnblogs.com/yeshaoxiang/p/12043714.html