问题
I know there were so many related questions like this one. But I didn't find any question that can solve my problem or I didn't find it yet. Umm...I am using three kind of browsers : Maxthon 4.4.2.2000 , Spark Security Browser 33.9.2000.3033, and Mozilla 32.0.3.
I'm using $.ajax()
to send data from my login form
Form
<form method="POST" id="login_data">
<table>
<tr>
<td>Username</td>
<td><input id="txt_user" type="text" name="txt_username"></td>
<td><label id="warn_username"></label></td>
</tr>
<tr>
<td>Password</td>
<td><input id="txt_password" type="password" name="txt_password"></td>
<td><label id="warn_password"></label></td>
</tr>
<tr>
<td colspan="1" />
<td><button name="login" id="lgn_button">Login</button></td>
</tr>
</table>
</form>
And my javascript is like this:
$(document).ready(function(){
$('#lgn_button').click(function(){
var user = $('#txt_user').val();
var password = $('#txt_password').val();
if(user==""){
alert('');
}
else{
$.ajax({
url: 'login.php',
type: 'POST',
data: {username:user,password:password},
success:function(){
}
});
}
});
});
The last one is my php file that connected to server to authenticate user
<?php
session_start();
include '../controls/connection.php';
include '../controls/function.php';
shout($_POST['username']);
open_connection($dbserver,$dbuser,$dbpass,$dbname);
$query = mysql_query('SELECT COUNT(user_name) FROM Euser WHERE user_name="'.$_POST['username'].'"');
$count = mysql_fetch_row($query);
if($count[0]==0){
}
else{
$query = mysql_query('SELECT * FROM Euser WHERE user_name="'.$_POST['username'].'"');
$check=mysql_fetch_assoc($query);
if($check['user_password']==md5($_POST['password'])){
$_SESSION[md5('user')]=$_POST['username'];
$_SESSION[md5('author')]=$check['user_authority'];
}
}
?>
For this function : open_connection()
, it's working fine. The problem is, this code is working fine in Maxthon browser only not in 2 others, why? Anybody can explain to me? I'm a newbie. Thanks a lot for every answer and I appreciate it.
来源:https://stackoverflow.com/questions/26189491/sending-data-to-php-via-ajax-is-not-working-in-every-browser