我使用JQuery如何JQuery的ajaxComplete HTML變化
我有以下jQuery代碼後保留現有的HTML:
//Submitting the form
$("#loginDetails > form").submit(function()
{
//Hiding the Login button
$("#loginButton").hide();
//Showing the ajax loading image
$("#ajaxloading").show();
// 'this' refers to the current submitted form
var str = $(this).serialize();
// -- Start AJAX Call --
$.ajax({
type: "POST",
url: "Login.aspx", // Send the login info to this page
data: str,
success: function(result)
{
$("#loginDetails").ajaxComplete(function(event, request, settings)
{
// Show 'Submit' Button
$('#loginButton').show();
// Hide Gif Spinning Rotator
$('#ajaxloading').hide();
var arr = result.split(",");
var fname = arr[0];
var lname = arr[1];
var activeCardNo = arr[2];
var multipleTier = arr[3];
var activeStatus = arr[4];
var access = arr[5];
if(access!='') // LOGIN OK?
{
var login_response = '<div id="logged_in">' +
'<div style="width: 350px; float: left; margin-left: 80px;">' +
'<div style="width: 40px; float: left;">' +
'<img style="margin: 22px 0px 10px 0px;" align="absmiddle" src="system/images/ajax-loader.gif">' +
'</div>' +
'<div style="margin: 24px 0px 0px 10px; float: right; width: 300px;">'+
"You are successfully logged in! <br /> Please wait while you're redirected...</div></div>";
$('#loginButton').hide();
$('#closeBtn').hide();
$('#divMember').text(fname +' '+ lname);
$('#spnSkywardsNo').text(activeCardNo);
$('#spnTierStatus').text(multipleTier);
$("#ui-dialog-title-skywardsLogin").text("Please wait...");
$(this).html(login_response); // Refers to 'status'
// After 3 seconds redirect the
setTimeout(closeDialog, 3000);
}
else // ERROR?
{
var login_response = result;
$('.validateTips').html(login_response);
}
});
}
});
// -- End AJAX Call --
return false;
});
//Login Button Clicked
$('#loginButton').click(function()
{
var bValid = true;
bValid = bValid && checkLength(skywardNo, "Skyward No", 3, 16);
bValid = bValid && checkLength(password, "password", 5, 16);
if (bValid)
{
$("#loginDetails > form").submit();
allFields.val("");
tips.text("");
}
});
在上面的jQuery代碼我呼籲dailog模式彈出點擊事件#loginButton按鈕,並在所有驗證我的表單提交後,在我上面的ajaxComplete請求中,我正在更新我現有的表單的「login_response」 html。
<div class="formContainer" id="loginDetails">
<form action="#" id="frmLogin" class="homeWidget">
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td class="formLabel" width="100">
<label for="skywardsNumber" title="Skywards Number">
Skywards Number</label></td>
<td>
<input class="formField" id="skywardsNumber" name="skywardsNumber" size="25" type="text" /></td>
<td class="formLink">
<a class="iconHelpBox" href="#">Forgot number</a></td>
</tr>
<tr>
<td class="formLabel">
<label for="password">
Password</label></td>
<td>
<input class="formField" id="password" name="password" size="25" type="password" /></td>
<td class="formLink">
<a class="iconHelpBox" href="#">Forgot password</a></td>
</tr>
</table>
</form>
</div>
以上HTML代碼如下HTML代碼替換
var login_response = '<div id="logged_in">' +
'<div style="width: 350px; float: left; margin-left: 80px;">' +
'<div style="width: 40px; float: left;">' +
'<img style="margin: 22px 0px 10px 0px;" align="absmiddle" src="system/images/ajax-loader.gif">' +
'</div>' +
'<div style="margin: 24px 0px 0px 10px; float: right; width: 300px;">'+
"You are successfully logged in! <br /> Please wait while you're redirected...</div></div>";
現在一切正常第一次,當我點擊登錄鏈接,但畢竟上述JQuery的活動時,我點擊第二次登錄鏈接相同的更新html即將到來。
請建議!
不知道這裏有什麼問題?任何時候單擊登錄鏈接時,如果登錄成功,不應該返回相同的login_reponse html片段?換句話說,第二次登錄鏈接被點擊時應該返回什麼? – 2010-12-16 12:23:32