ajax中基本参数应用

$(function () {
$("#verificationCodeBtn").click(function () {
$("#verificationCodeImage").attr("src",ctx + "/verificationCode?v=" + new Date());
});

$("#loginBtn").click(function () {
$.ajax({
type : "POST", //请求方式:POST/GET
url : ctx + "/doLogin", //请求地址
dataType : "json", //服务器返回的数据类型(text/xml/json)
data : { //传给服务器的参数
username : $("#username").val(),//获取页面中的username值,传给对应的 controller层
password : $("#password").val(),//获取页面中password值,传给对应的 controller层
                verificationCode : $("#verificationCode").val()//这个是验证码中的,和你没关系
},
success : function (result) { //成功回调的方法,result为返回值json数据
console.log(result);
if(result.status == 0){
window.location = "/index";
}else {
var msg = "<span style='color: red;'>" + result.message + "</span>"
$(".login-box-msg").html(msg);
}
},
error : function (error) { //失败回调方法,error也是返回值json数据
console.log(error);
}
});
});
});
这只是例子你只要看你需要的就OK了
原文地址:https://www.cnblogs.com/jingluu/p/8951211.html