我使用JS ajax和PHP進行遊戲即時通訊的登錄和註冊系統。是ajax實際工作?
我的問題是我不知道ajax請求實際上正在處理我指向它的php代碼。當我運行代碼時,網頁上發生了正確的事情,但是我已經將一個var_dump()放入了php中,以確保數據實際存在,但是我沒有在網頁上顯示從php上的任何內容,就像您通常使用var_dump ()
赫雷什使用HTML IM:
<article id="container">
<div id="load-new" class="game_menu">
<h1>LOAD/NEW</h1>
</div>
<div id="reg" class="game_menu">
<h1>REGISTER</h1>
<form name="register" method="post" action="">
<label for="usernamesignup" class="uname">Your username</label>
<input id="usernamesignup" name="usernamesignup" required="required" type="text" placeholder="Username" />
<label for="emailsignup" class="youmail"> Your email</label>
<input id="emailsignup" name="emailsignup" required="required" type="email" placeholder="[email protected]"/>
<label for="passwordsignup" class="youpasswd">Your password </label>
<input id="passwordsignup" name="passwordsignup" required="required" type="password"/>
<label for="passwordsignup_confirm" class="youpasswd">Please confirm your password </label>
<input id="passwordsignup_confirm" name="passwordsignup_confirm" required="required" type="password"/>
<button id="reg_submit" type="button">Register</button>
</form>
</div>
<div id="login" class="game_menu">
<h1>LOGIN</h1>
<form name="login" method="post" action="">
<label for="username" id="username_label">Username:</label>
<input type="text" name="username" id="username" value=""/>
<label for="password" id="password_label">Password:</label>
<input type="password" name="password" id="password" value=""/>
<button id="login_submit" type="button">Login</button>
</form>
</div>
<div id="access" class="game_menu">
<h1>ACCESS</h1>
<button id="login_but" type="button">Login</button>
<button id="reg_but" type="button">Register</button>
</div>
繼承人與AJAX請求使用JS IM:
this.login_ajax = function()
{
var username = $("#username").val();
var password = $("#password").val();
var dataString = 'username='+ username + '&password='+ password;
alert(dataString);
$.ajax({
type:"POST",
url:"PHP/login.php",
data: dataString,
success: function() {
$('#login').hide();
$('#load-new').show();
},
error: function(){
alert("ERROR");
}
});
};
,這裏是PHP文件是運行:
if ((isset($_POST['username'])) && (strlen(trim($_POST['username'])) > 0)) {
$username = stripslashes(strip_tags($_POST['username']));
} else {$username = 'No username entered';}
if ((isset($_POST['password'])) && (strlen(trim($_POST['password'])) > 0)) {
$password = stripslashes(strip_tags($_POST['password']));
} else {$password = 'No password entered';}
var_dump($username);
就像我說的,ajax請求返回成功,但即時通訊從PHP文件,這讓我覺得,沒有轉儲是實際運行的PHP文件?
謝謝
在你的if語句之前爲'$ username'賦值,因爲如果這些失敗了,它會拋出'var_dump()'什麼都沒有,你不知道腳本是否正在運行。 – mcryan 2013-03-09 20:38:25
我剛剛做了你所說的%username = hello然後var_dumped striaght後,並沒有它被拒絕屏幕 – 2013-03-09 20:54:42