我想在数据库中保存数据,我使用angular和我用文件php来访问数据库,问题是:POST http://127.0.0.1:9090/insert_indispo.php 405(Method Not Allowed)..请问如何解决这个问题! ......
这里是我的职能发布:
function ValideConge(id,debut,fin) {
var deferred = $q.defer();
$http({
method: 'POST',
url: window.location.href + 'insert_indispo.php',
data: {id,debut,fin},
headers: { 'Content-Type': 'application/json' }
}).then(function (success){
deferred.resolve("ok!");
console.log("ok c!");
},function (error){
deferred.resolve(false);
console.log("ok n!");
});
return deferred.promise;
}
这里是我的文件php:
<?php
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, POST, OPTIONS');
$postdata = file_get_contents("php://input");
$request = json_decode($postdata);
$id = $request->id;
$debut = $request->debut;
$fin = $request->fin;
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "plann";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "INSERT INTO indisp (id_form,date_debut,date_fin)
VALUES ( $id, $debut , $fin)";
if ($conn->query($sql) === TRUE) {
echo "ajouté avec succé !";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
$conn->close();
?>