Last active
January 19, 2019 11:08
-
-
Save ayuLiao/42733b83d37845838f7db73d1cdcf261 to your computer and use it in GitHub Desktop.
使用 $.ajax 做ajax请求
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var onLoginSuccess = function (data) { | |
location.reload(); | |
} | |
$("#changemaintain").click(function(){ | |
var p = $('#changemaintain').val(); | |
if(p == '0'){ | |
p = '1'; | |
}else{ | |
p = '0'; | |
} | |
params = {'maintain': p} | |
var ajaxObj = { | |
type: 'POST', | |
url: 'http://127.0.0.1:5002/lucky', //URL上一定要带HTTP,不然报错 | |
data: params, | |
success: onLoginSuccess, //ajax成功,前端的回调函数 | |
dataType: "json" | |
}; | |
$.ajax(ajaxObj); | |
}) | |
//通过方法封装AJAX | |
$.ajaxPost = function(url, data, callback) { | |
$.post(url, data, callback, "json"); | |
}; | |
$.ajaxPost('/post/ajaxUrl',{},function(data){}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment