jquery-Ajax

来源:互联网 发布:卡迪夫城市大学 知乎 编辑:程序博客网 时间:2024/05/23 19:13

$.ajax()

.ajax(url[,setting])使[.ajax的参数](http://jquery.cuishifeng.cn/jQuery.Ajax.html)

    $.ajax({       type: "POST",       url: "some.php",       data: "name=John&location=Boston",       success: function(msg){         alert( "Data Saved: " + msg );       }    });

load()

$(E).load(url, data, callback) 载入远程 HTML 文件代码并插入至 DOM 中,默认使用 GET 方式 - 传递附加参数时自动转换为 POST 方式

$(function(){    $('button').click(function(){        $('div').load('index.php', {name:"123"}, function(){            alert('success');        })    });});

$.get()

$.get(url, data, callback, type)

$(function(){    $('button').click(function(){        $.get('index.php', {name: "123"}, function(data){            console.log(data);        }, 'json');    });});

$.post()

$.post(usrl, data, callback, type)

$.getJSON()

$.getJSON(url, data, callback)请求返回json数据

$(function(){    $('button').click(function(){        $.getJSON('index.php', {name: "123"}, function(data){            console.log(data);        }, 'json');    });});

$.getScript()

$.getScript(url, callback)通过 HTTP GET 请求载入并执行一个 JavaScript 文件,并能跨域执行

$(function(){    $('button').click(function(){        $.getScript('farst.js', function(){            alert('success');        });    });});

ajaxComplete()

当ajax请求执行完成后才会执行,不论成功失败,但是1.8以后仅仅能被绑定到document上

$(function(){        $(document).ajaxComplete( function(event, jqXHR, options){            alert("处理函数1:请求的url为");        } );        $(document).ajaxComplete( function(event, jqXHR, options){            alert("处理函数2:请求方式为");        } );        $.post('index.php');    })

ajaxError()

当执行ajax发生错误时执行,1.8以后仅仅能监听document

$(function(){    $(document).ajaxError( function(event,request, settings){        alert("出错处理1");    } );    $(document).ajaxError( function(event,request, settings){        alert("出错处理2");    } );    $.post('index2.php');})

ajaxSend()

当执行ajax发送前执行,1.8以后仅仅能监听document

jQueryajaxStart()

当执行ajax开始执行时执行,1.8以后仅仅能监听document

ajaxStop()

AJAX 请求结束时执行函数,1.8以后仅仅能监听document

ajaxSuccess()

AJAX 请求成功时执行函数,1.8以后仅仅能监听document

$.ajaxSetup({})

设置全局 AJAX 默认选项

$(form).serialize()

序列化表单值,创建 URL 编码文本字符串

$(form).serializeArray()

序列化为对象数组

0 0