當我嘗試檢查用戶輸入名稱是否已經存在時,通過ajax表單提交!但它只在sessions.php
中得到Undefined index: username
,缺什麼?
<form action="" method="POST" id="saveuser" enctype="multipart/form-data">
<input type="text" name="username"><br>
<input type="password" name="pass"><br>
<input type="file" name="fileupload"><br>
<input type="submit" name="submit" value="Confirm" id="confirm">
</form>
<script type="text/javascript">
$('#confirm').click(function(e){
e.preventDefault();
$.ajax({
type:'POST',
url :"sessions.php",
data:$("#saveuser").serialize(),
contentType : false,
processData: false,
success: function(d){
console.log(d);//[error] :Undefined index: username
}
});
});
</script>
sessions.php
<?php
$exist = "david";
if($_POST['username'] == $exist){
echo json_encode("Already exist");
}
else{
echo json_encode("You can succesfully add");
}
?>
寫的print_r($ _ POST);在session.php中,你找到該數組中的用戶名? –
是你在同一頁中的表格 –
我有空陣列,但在網絡選項卡上,我可以看到我的參數! @Kaushalshah –