为什么我PHP传回的xmlhttp.responseText是一个文本档??如图
我的AJAX代码varxmlhttp=false;try{xmlhttp=newActiveXObject("Msxml2.XMLHTTP");}catch(e){try...
我的AJAX 代码
var xmlhttp = false;
try {
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e2) {
xmlhttp = false;
}
}
if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
xmlhttp = new XMLHttpRequest();
}
function Ajax(data){
var url="js/user_ck.php";
url=url+"?q="+data.value+"&sid="+Math.random();
xmlhttp.open("GET",url,true);
xmlhttp.send(null);
document.getElementById('username_notice').innerHTML = process_request;//显示状态
xmlhttp.onreadystatechange=function(){
if (4==xmlhttp.readyState){
alert(xmlhttp.status);
if (200==xmlhttp.status){
var responseText = xmlhttp.responseText;
alert('11111');
alert(responseText);
if (responseText=="true" ){
alert('2222222');
ck_user("true");
}
else{
alert('33333');
ck_user("false");
}
}else{
alert("发生错误!");
}
}
}
}
PHP代码:
<?php
//header('Content-Type:text/html;charset=utf-8');
// header("Cache-control: no-cache");
session_start();
$q=$_GET['q'];
//$q='luan';
//echo $q;
//error_reporting(0);
$con = mysql_connect("localhost","root","123456");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("LFsystem", $con);
$sqlstr="SELECT * FROM user where username='".$q."'";
$result =mysql_query($sqlstr);
//echo $result;
if($result==null){
echo ('true');
}else {
echo ('false');
}
mysql_close($con);
?> 展开
var xmlhttp = false;
try {
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e2) {
xmlhttp = false;
}
}
if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
xmlhttp = new XMLHttpRequest();
}
function Ajax(data){
var url="js/user_ck.php";
url=url+"?q="+data.value+"&sid="+Math.random();
xmlhttp.open("GET",url,true);
xmlhttp.send(null);
document.getElementById('username_notice').innerHTML = process_request;//显示状态
xmlhttp.onreadystatechange=function(){
if (4==xmlhttp.readyState){
alert(xmlhttp.status);
if (200==xmlhttp.status){
var responseText = xmlhttp.responseText;
alert('11111');
alert(responseText);
if (responseText=="true" ){
alert('2222222');
ck_user("true");
}
else{
alert('33333');
ck_user("false");
}
}else{
alert("发生错误!");
}
}
}
}
PHP代码:
<?php
//header('Content-Type:text/html;charset=utf-8');
// header("Cache-control: no-cache");
session_start();
$q=$_GET['q'];
//$q='luan';
//echo $q;
//error_reporting(0);
$con = mysql_connect("localhost","root","123456");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("LFsystem", $con);
$sqlstr="SELECT * FROM user where username='".$q."'";
$result =mysql_query($sqlstr);
//echo $result;
if($result==null){
echo ('true');
}else {
echo ('false');
}
mysql_close($con);
?> 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询