Jquery中ajax基本语法

泄露秘密 提交于 2019-12-15 12:34:34
一.$.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;
    }
    //代码处理
});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!