【发布时间】:2018-01-18 10:07:41
【问题描述】:
我对 angularjs 中的 $http 有疑问:
app.controller('ctrlProfil', function($scope, $http){
$scope.loginProfil = "<?= $_SESSION['login']?>";
$scope.mdpProfil = "<?= $_SESSION['mdp']?>";
$scope.emailProfil = "<?= $_SESSION['email']?>";
var config = {
method: 'POST',
url: 'modifProfil.php',
data: $('#formProfil').serialize()
}
$scope.submit = function(){
$http(config).
then(function(response){
console.log(response);
console.log($('#formProfil').serialize());
})
}
});
我的表格 =>
<form id="formProfil" ng-submit="submit()">
<p><span>Bonjour </span><input type="text" name="loginProfil" value="{{loginProfil}}"/></p>
<p>Mon mot de passe: <input type="text" name="mdpProfil" value="{{mdpProfil}}"/></p>
<p> Email: <input type="email" name="emailProfil" value="{{emailProfil}}"/></p>
<input class="btn btn-primary" type="submit" value="Enregistrer"/>
</form>
我的 php 代码 =>
try
{
$db = new PDO('mysql:host=localhost;dbname=monprojet;charset=UTF8', 'root', 'root');
}
catch(Exception $e)
{
die('Erreur : '.$e->getMessage());
}
$login = $_POST['loginProfil'];
$mdp = $_POST['mdpProfil'];
$email = $_POST['emailProfil'];
$rep = $db->query('SELECT id FROM utilisateur WHERE login='.$_SESSION['login']);
$reponse = $db->prepare('UPDATE utilisateur SET login= :login, mdp= :mdp, email= :email WHERE id='.$rep);
$reponse->execute(array(
':login' => $login,
':mdp' => $mdp,
':email' => $email
));
$json = json_encode($reponse->fetchAll());
$reponse->closeCursor();
echo $json;
我无法通过 $http(config) 发送数据,我有一个错误告诉我:
注意:未定义索引:loginProfil in /Applications/MAMP/htdocs/izad/git/modifProfil.php 第 15 行
注意:未定义的索引:mdpProfil in /Applications/MAMP/htdocs/izad/git/modifProfil.php 第 17 行
注意:未定义索引:emailProfil in /Applications/MAMP/htdocs/izad/git/modifProfil.php 第 19 行
但我的索引已定义,需要一些帮助才能理解这一点
谢谢
【问题讨论】:
-
在 Angular 前端应用程序中使用 php 代码是一个大错误...我认为您并不真正了解客户端/服务器端语言之间的区别...
标签: javascript php angularjs angular-promise