How do I make the PHP file cause AJAX to fail?

0

Good.
I'm trying to make a program that looks at whether the password of a form is in a file.txt.

The file is line by line in this way:

  

000
010
001
...

Keep this up with a lot of passwords but it's for you to come to the idea.

My code of AJAX where $ ("# pass" would be where is the password):

    $("#pass").on("change",function(){
        var data = $("#pass");
        var request = $.ajax({
            url:'egiaztatuPosta.php',
            data: data,
            dataType:'html'
        });
        request.done(function(data){
            echo("No está dentro");
        });
        request.fail(function(data){
            echo("Está dentro");
        });
    });



My code PHP :

$pasahitzak = fopen('../DATUAK/toppasswords1.txt','r');
$aurk=false;
$zenb=0;
while($linea = fgets($pasahitzak)){
    $aux[] = $linea;
     echo "<script>console.log( 'Pasahitza: " . "$_REQUEST[pasahitza]" . "' );</script>\n";
     echo "<script>console.log( 'Lerroa: " . $linea . "' );</script>\n";
    if("$_REQUEST[pasahitza]"==$linea){
        $aurk=true;
    }
    echo "<script>console.log( 'Finala: " . $ald . "' );</script>";
}

fclose($pasahitzak);

What I want to know is if there is any way for the AJAX to perform the fail function when $ aurk equals true ($ aurk = true). I think that with those two bits of code is enough to expose my doubt. If you need some more code because it's not enough, put it in the comments.
I have not found anything useful and that's why I ask. Greetings.

    
asked by Mikel Molinuevo 30.11.2017 в 22:50
source

1 answer

1

The data is what you come back from the php, so you do

$pasahitzak = fopen('../DATUAK/toppasswords1.txt','r');
$aurk=false;
$zenb=0;
while($linea = fgets($pasahitzak)){
    $aux[] = $linea;
     echo "<script>console.log( 'Pasahitza: " . "$_REQUEST[pasahitza]" . "' );</script>\n";
     echo "<script>console.log( 'Lerroa: " . $linea . "' );</script>\n";
    if("$_REQUEST[pasahitza]"==$linea){
        echo "true";
    }
    echo "false";
}

fclose($pasahitzak);

When making the callback done, you should bring it in the data

 request.done(function(data){
    if(data == true) {
        //aquí va tu código
     } else {
       //aquí va si no
     }


 });
    
answered by 30.11.2017 / 22:58
source