ajax的写法

方法一:

$.ajax({
    url:'',
    type:'',
    dataType:'',
    data:'',
    headers:'',
    success:function(msg){
        
    },
    error: function(msg){
        
    }
});

方法二:get请求简写

$.get(url,function(msg){
    
});

方法三:post请求简写

$.post(url,data,function(msg){
    
});

方法四:提交上传文件

$(this).ajaxSubmit({
    url:'',  
    type:'',
    dataType:'',
    data:'',
    headers:'',
    success:function(msg){   
    },
    error: function(msg){
        
    }
})
return false;  //阻止主动第二次提交

方法五:前端有多个值需要获取

$('#form-house-info').submit(function () {
    var a = $(this).serialize() //获取多个值
    $.post('/house/newhouseinfo/', a ,function (data) {
​
        if (data.code == '200'){
            location.href = '/house/myhouse/'
        }
    });
    return false;
});
原文地址:https://www.cnblogs.com/kk138/p/14850361.html