我很猶豫要問,但我還沒有找到任何解決方案。在ajax函數中發送php文件中的數據之後,當我嘗試捕獲php文件中的數據時,數據丟失。但是,昨天我發現了一個沒有問題的類似功能。 這是AJAX部分:file_get_contents(「php:// input」)後ajax後空
$http({
url: 'PDO/Companion.php',
data: {
Companion : Companion,
Companion : statut
},
method: 'POST',
headers : {'Content-Type':'application/x-www-form-urlencoded; charset=UTF-8'}
}).then(function (response) {// on success
$scope.name=undefined;
$http.get('js/controller/upPartenaire.php').success(function(data) {
$scope.result = data;
console.log(data);
}), function(msg){
console.log("ça")
alert(msg);
};
,而PHP的一部分:
$postdata = file_get_contents("php://input");
$request = json_decode($postdata);
echo json_encode($request);
在項目中,我使用PHP只針對AJAX部分做SQL queryI也趕上與$ _ POST,但沒有數據
您是否已完成盡職調查並使用瀏覽器開發人員控制檯和網絡選項卡調試了ajax調用?你是否積極發送數據,並且沒有控制檯錯誤? – IncredibleHat
您還應該包含'var Companion'和'statut'定義的代碼,並解釋您爲什麼試圖將「Companion」的數據鍵名發送兩次。最後,如果您加載了jquery庫,那麼爲什麼不使用'$ .post'來簡化很多? [JQuery的.post](https://api.jquery.com/jquery.post/) – IncredibleHat