I am trying to call the
php script with the help of
AJAX and send some values acquired from an
html form. My code editor is
Microsoft Visual Studio Code.
My code:
function submit(a,b,c,d,em){
console.log(a+" "+b+" "+c+" "+d+" "+em)
$.ajax({
type : "POST",
url : "script.php",
data : { a:a, b:b, c:c, d:d, e:em },
success: function(){
alert("ok");
}
});
}
const dForm = document.getElementById('form');
dForm.addEventListener('submit', function(e) {
e.preventDefault()
submit(a,b,c,d,em);
});
When I run the script, I get this error in the console:
Failed to load resource: the server responded with a status of 405 (Method Not Allowed)
Please help me in fixing this.
Here's my php script:
<?php
header('Access-Control-Allow-Origin: *');
header("Access-Control-Allow-Methods: GET, POST, OPTIONS");
if (isset($_POST["a"]))
$val_1=$_POST['a'];
if (isset($_POST["b"]))
$val_2=$_POST['b'];
if (isset($_POST["c"]))
$val_3=$_POST['c'];
if (isset($_POST["d"]))
$val_4=$_POST['d'];
if (isset($_POST["e"]))
$val_5=$_POST['e'];
?>
What I have tried:
Included both the core headers, but still it doesn't work (in my
php scirpt).