首页 > 程序开发 > web前端 > JavaScript >

Jquery Ajax格式(备查)

2013-11-22

$() ready(function () { $(" login_button") click(function () { if($(" username") val()==null||$(" username") val()==& 39;& 39;){ alert("用户名不能为空"); $(& 39;

$().ready(function () {
$("#login_button").click(function () {
if($("#username").val()==null||$("#username").val()==''){
//alert("用户名不能为空");
$(&#39;#loginErrorMessage&#39;).html(&#39;<p style="font-color:red;">用户名不能为空</p>&#39;);
return false;
}else if($("#password").val()==null ||$("#password").val()==&#39;&#39;){
//alert("密码不能为空");
$(&#39;#loginErrorMessage&#39;).html(&#39;<p style="font-color:red;">密码不能为空</p>&#39;);
return false;
}else{
$.ajax({
url: "/BRoute/MemberLogin/login/?"+Math.random(),
error: function(msg) { alert(msg); },
complete: function (data) {
},
data: {username: $("#username").val(), password: $("#password").val()},
dataType: "json",
type: "get",
success: function (data) {
if(data.message=="success"){
//window.location="/BRoute/MemberLogin/checkSession?"+Math.random();
history.back();
//location.reload();
//location.replace(document.referrer);
}
else{
// alert("用户名和密码不匹配");
$(&#39;#loginErrorMessage&#39;).html(&#39;<p style="font-color:red;">用户名和密码不匹配</p>&#39;);
}
}
});
}
});
});
$(document).ready(function () {
$.getJSON("/BRoute/MemberLogin/checkSession/?" + Math.random(), null, function (data) {
//alert(data.message);
if (data.message == "please login") {
//$(&#39;#huanying&#39;).html(&#39;<a href="http://localhost:20705/membermanage/memberlogin" class="B12-A" style="color:#006db6;">登录</a>&#39;);
//$(&#39;#logout&#39;).html(&#39;<a href="http://localhost:20705/membermanage/becomeMember" class="B12-A" style="color:#006db6;">注册</a>&#39;);
}
else {
var username = data.message;
$(&#39;#huanying&#39;).html(&#39;<a href="javascript:goto(0)" class="B12-A" style="color:#006db6;">欢迎您: &#39; + username + &#39;!</a>&#39;);
// $(&#39;#logout&#39;).html(&#39;<a href="javascript:logout()"class="B12-A" style="color:#006db6;">退出</a>&#39;);
// $(&#39;#huanying&#39;).appendTo("<li id = &#39;logout&#39;><a href=&#39;javascript:logout()&#39; style=&#39;color:#006db6;&#39;>退出</a></li>");
$("<li id = &#39;logout&#39;><a href=&#39;javascript:logout()&#39; style=&#39;color:#006db6;&#39;>退出</a></li>").insertBefore($(&#39;#huanying&#39;));
}
});
});
function logout() {
$.ajax({
url: "/BRoute/MemberLogin/logout/?" + Math.random(),
error: function (msg) {
alert(msg);
},
complete: function (data) {
},
data: null,
dataType: "json",
type: "get",
success: function (data) {
window.location = "/?" + Math.random();
location.reload();
}
});
};
相关文章
最新文章
热点推荐