I'm new to web development and I'm struggling with "Access to XMLHttpRequest" problem since 2 days.
There are 4 files : index.html, validate.js, style.css and singup.php.
Inside index.html I just have a code for a form with inputs. Style.css we can skip. Validate.js is below:
function validate(){
if ( email == null && password == null){
alert ("Please fill the details.");
return false;
}
else{
$.ajax({
type: "POST",
url: "signup.php",
data: { email , password},
cache: false,
success: function(html) {
alert(html);
}
});
}
Code from signup.php :
$db = mysqli_connect('localhost', 'root', '' , 'game'); $email = $_POST['email']; $password2 = $_POST['password']; $password = md5($password2); $sql = "INSERT INTO users ( email, password) VALUES ( '$email', '$password')"; $result = mysqli_query ($db, $sql);
Actually 2 days ago it was working fine. I could submit form and I could see new input in database. I made laptop asleep and then tried next day and it just doesn't work anymore.
I try ctrl+shift+i and I see errors:
Access to XMLHttpRequest at 'file:///C:/Program%20Files%20(x86)/EasyPHP-Devserver-17/eds-www/signup.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. signup.php:1 ```
Failed to load resource: net::ERR_FAILED
Tried all possible ways which I found (like extensions to Chrome Browser and cmd with "--allow-file-access-files") but it's still the same.
How is it even possible that something works one day and doesn't work next day?