以下是從Smarty的模板,我的HTML代碼:我的jquery-ajax代碼有什麼問題,因此無法正常工作?
<div id="user-popup-login" title="Demo Test Packages">
<div id="pop-up">
<!--<div class="popup-right"><img src="images_new/close.gif" alt=" " align="right" width="29" height="29" /></div>
<div class="clear"></div>-->
<div class="error_msg" id="login_error" style="text-align:center; margin-top:5px;">
</div>
<div class="clear"></div>
<div class="popup-left">
<form name="user_login_form" id="user_login_form" class="login_box" method="post" action="{$site_url}login">
<input type="hidden" name="referral_url" value="{$referral_url}" id="referral_url" />
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td colspan="2"><input name="user_name" id="user_name" class="user" type="text" value="E-mail" onblur="if(this.value=='') this.value='E-mail';" onfocus="if(this.value=='E-mail') this.value='';" />
</td>
</tr>
<tr></tr>
<tr>
<td colspan="2"><input name="user_password" id="user_password" class="user" type="password" value="password" onblur="if(this.value=='') this.value='password';" onfocus="if(this.value=='password') this.value='';" />
</td>
</tr>
<tr></tr>
<tr>
<td><input name="Submit" type="submit" class="login-btn" value="" /></td>
<td><div id="registern"><a href="#" class="register-btn">Register Now</a></div></td>
</tr>
<tr>
<td align="right" colspan="2"><a href="{$site_url}forgot_password.php?op=forget_password" class="forget">Forgot Password? </a> </td>
</tr>
</table>
</form>
</div>
<!--<div class="popup-right"><img src="images_new/facebook-sign.gif" alt=" " width="156" height="229" /></div>-->
<div class="clear"></div>
</div>
</div>
以下是我的jQuery代碼:
<script language="javascript" type="text/javascript">
$(function() {
$("#user-popup-login").dialog({ autoOpen: false });
$(".user-not-loggedin")
.click(function() {
$("#user-popup-login").dialog("option", "width", 400);
$("#user-popup-login").dialog("option", "modal", true);
$("#user-popup-login").dialog("open");
return false;
});
$(".get-start")
.click(function() {
$("#user-popup-login").dialog("option", "width", 400);
$("#user-popup-login").dialog("option", "modal", true);
$("#user-popup-login").dialog("open");
return false;
});
//This function is used to submit User Login form
$('#user_login_form').live('submit', function() {
$('.login-btn').attr('disabled', 'disabled');
show_request('#login_error');
$.ajax({
type: $(this).attr('method'),
url: $(this).attr('action'),
data:$(this).serialize(),
dataType: 'json',
success: function(response) {
$('.login-btn').removeAttr('disabled', 'disabled');
var log_error = response.log_error;
if(log_error=='yes') {
var error_msg = response.error_msg;
var dialog_title = 'Input Errors Found';
var dialog_message = error_msg;
$("#login_error").html(error_msg);
} else {
$("#login_error").html('');
$("#user-login").dialog('close');
var suc_msg = response.suc_msg;
var dialog_title = 'Logged in Successfully';
var dialog_message = suc_msg;
var $dialog = $("<div class='ui-state-success'></div>")
.html("<p class='ui-state-error-success'>"+dialog_message+"</p>")
.dialog({
autoOpen: false,
modal:true,
title: dialog_title,
width: 500,
buttons:{
'OK': function() {
$(this).dialog('close');
}
}
});
$dialog.dialog('open');
$('#user_login_form')[0].reset();
}
}
});
return false;
});
});
</script>
我的名爲user_login.php PHP文件它有一個唉名登錄這是在使用行動屬性有以下代碼:
<?php
include_once("includes/application-header.php");
prepare_request();
$obj_login = new Login();
if($gSession->ReadFromSession('IS_LOGGEDIN') && $_GET['act'] !='logout') {
header("location:".SITE_URL."home");
die();
} else {
if("POST" == $_SERVER['REQUEST_METHOD']) {
$login_data = extract_array($_POST , array("user_name", "user_password"));
$user_id = $obj_login->DoUserLogin($login_data);
if($user_id) {
list($subscription_type, $days_left) = $gUsers->GetUserSubscriptionDetailsByUserID($user_id);
if($gUsers->InitiateUserSession($user_id, $subscription_type, $days_left)) {
$gUsers->UpdateUserLoginHistory($user_id);
$reponse_data['login_error'] = 'no';
$reponse_data = json_encode($reponse_data);
echo $reponse_data;
die();
}
} else {
$error_msg = $obj_login->GetError();
list($login_data) = prepare_response($login_data);
$error_msg = '<b>We are unable to log you in for one of the following reasons:</b>
</p>
<ul>
<li>Incorrect email or password (case sensitive)</li>
<li>Cookies are not enabled on your browser</li>
<li>You havent registered with entrance prime</li>
<li>We have not activated your account</li>
</ul><p></p>';
$reponse_data['login_error'] = 'yes';
$reponse_data['error_msg'] = $error_msg;
$reponse_data = json_encode($reponse_data);
echo $reponse_data;
die();
}
}
// CODE FOR LOGOUT
if(isset($_GET['act']) && $_GET['act']=='logout') {
$gUsers->UpdateUserLogoutHistory();
$obj_login->UserLogout();
header("Location:".SITE_URL."home");
die();
}
}
?>
我的問題是當我點擊登錄按鈕時沒有填寫任何值,表單提交時沒有一個ny錯誤,並在彈出窗口中顯示「未定義」,而不是向我顯示錯誤。任何人都可以幫我解決這個問題嗎?
您使用的是哪個版本的jQuery? v1.9中刪除了「live」。您在瀏覽器的JavaScript控制檯中是否收到錯誤信息? –
@ T.J.Crowder:是的,我知道。我使用的是支持live的jQuery 1.4.1。所以我沒有得到任何錯誤。 – PHPLover
@ T.J.Crowder:不幸的是,這是不可能的。我現在只能使用1.4.1。 – PHPLover