0

I have a problem with my form (made with jquery, php, html) when submitting:

   <?php

    $pass ="password";
    $login = "login";

    $t = array();
    $t["error"]="Formulaire Incorrect";
    if($_POST["login"]!= $login){
    $t["errorLogin"] = "Identifiant Invalide!";
    }
    else{
    if($_POST["password"]!=$pass){
        $t["errorPass"]="Mot de pass incorrect!";
    }
    else{
    $t["error"]="no";
    $t["retour"] = "<p>Informations validées</p>!";
    }
    }
    echo json_encode($t);
    ?>

jquery-1.12.4.min.js:4 Access to XMLHttpRequest at 'file:///C:/Users/Medinfo/Desktop/JQUERY/JSON/check.php' from origin 'null' has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https.

AbraCadaver
  • 78,200
  • 7
  • 66
  • 87

1 Answers1

0

For PHP code to be able to run you should run it on a server. You are requesting a source that starts with file:///. It should start with something like https or http.

To run PHP locally on your PC try tools like XAMPP or WAMP.

Edit: I see now, you said your PHP is running on your localhost. That's great. Move your PHP file to the folder of XAMPP or WAMP (should be something like C:\xampp\htdocs). And then make your request go to something like http://localhost:8000/somefolder/check.php

Tafel
  • 1,017
  • 10
  • 17