doutao4938 2015-10-20 16:50
浏览 122
已采纳

AJAX / PHP / JS readyState = 1和Status = 0总是。 没有回复文字

I've been trying lately to use this sample of AJAX to compare form data to an SQL database from one http://www.example.com domain. My issue is that the readyState is always 1 and my Status is always 0. It is expecting 4 and 200 respectively. It also always returns responseText="" I've looked all over StackOverflow but have unsuccessfully found anything helpful.

I've boggled my mind over what could be the issue, but I just can't seem to get it to work.

*I've also tried to set file permissions on both the JS and PHP, but it functions the same.

*I'm using a dedicated web server to host all this, and I have no problem running most scripts.

//HTML GenerateRep.html

Excuse the lack of < and > tags missing, the code won't appear without them.

form id="formgen" onsubmit="GenRep(this)"
....form stuff....
button id="submit" type="submit">Submit</button

//JAVASCRIPT GenerateRep.js

function GenRep(formgen) {

var email = formgen['repemail'];
var hash = formgen['reppass'];
var first = formgen['firstname'];
var last = formgen['lastname'];
var territory = formgen['territory'];

hash.value = CryptoJS.SHA256(hash.value);

var login = email + ";" + hash.value + ";" + first + ";" + last + ";" + territory;

Login(login);


}

function Login(login) {
    var xhttp = new XMLHttpRequest();
        xhttp.onreadystatechange = function() {
            if (xhttp.readyState == 4 && xhttp.status == 200) {
                if(xhttp.responseText == "VALID") {
                    window.location.href = "success.html";
                } else if (xhttp.responseText == "INVALID") {
                    $("#login_error").text("Failed! Plese check your info.");
                } else {
                    window.location.href = "error.php";
                }
            }
};
xhttp.open("GET", "Validate.php?q=" + login, true);
xhttp.send();
}

//PHP Validate.php

<?php
header('Access-Control-Allow-Origin: *');
include ("ConnectDB.php");

// Check connection

if ($conn->connect_error) {

die("Connection failed: " . $conn->connect_error);

} 

//THIS IS A TEST TO SEE IF reponseText FUNCTIONS. IT DOES NOT. 
//echo "testecho";


$whole = $_REQUEST['q'];

$userPass = explode (";", $whole);


$sql1 = "SELECT UName FROM Reps WHERE UName = '$userPass[0]'";
$result = $conn->query($sql1);

if ($result->num_rows > 0) {
$conn->close();
echo "INVALID";

} else {

$sql = "INSERT INTO Reps (UName, Pass, FName, LName, Territory) VALUES ('$userPass[0]', '$userPass[1]', '$userPass[2]', '$userPass[3]', $userPass[4])";

if ($conn->query($sql) === FALSE) {
$conn->close();
echo "Error: " . $sql . "<br>" . $conn->error;

}


$conn->close();
echo "VALID";

}
?>
  • 写回答

1条回答 默认 最新

  • dongyang4615 2015-10-23 20:04
    关注

    I previously "commented" instead of creating an "Answer" because I wasn't suggesting a fix, just a debug step to make sure what you thought was happening, was actually happening.

    Since my suggestion helped you figure out the problem, I created this "Answer" in case you want to give me "credit". :-)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)