$.ajax的beforeSend,success, complete,error例子

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/Cryhelyxx/article/details/53184540

jquery ajax官方文档: http://api.jquery.com/jquery.ajax/

常用的ajax形式:

$.ajax({
    url: "http://192.168.2.46:8000/account/getjson/",
    type: "post",
    dataType: "json", // 跨域使用jsonp
    contentType: "application/x-www-form-urlencoded; charset=UTF-8",
    data: {
        "user": "admin",
        "password": "123456"
    },
    beforeSend: function(XMLHttpRequest) {
        // do something...
        return true;
    },
    success: function(data) {
        // alert(JSON.stringify(data));
        // do something...
    },
    complete: function(XMLHttpRequest, textStatus) {
        // textStatus的值:success, notmodified, nocontent, error, timeout, abort, parsererror  
    },
    error: function(XMLHttpRequest, textStatus, errorThrown) {
        // textStatus的值:null, timeout, error, abort, parsererror
        // errorThrown的值:收到http出错文本,如 Not Found 或 Internal Server Error
    }
});

猜你喜欢

转载自blog.csdn.net/Cryhelyxx/article/details/53184540