我对angular很陌生
我创建了一个模式窗口来用户分享故事,然后在正文中显示:
html
<button class="btn btn-primary new-story" ng-click="showPopup()">New Story</button>
<div class="wroteStory img-rounded" ng-repeat="story in sentCompose">
<h1 class="s-label"><i><label for="subject">Subject :</label></i></h1>
<h5>{{story.subject}}</h5>
<h1 class="s-label"><i><label for="body">Full Story :</label></i></h1>
<h6>{{story.body}}</h6>
<button class="btn btn-danger" ng-click="remove($index)"> Delete </button>
<hr/>
</div>
js
app.controller('aboutController', function($scope,ngProgress) {
$scope.popupVisible = false;
$scope.showPopup = function(){
$scope.popupVisible = true;
$scope.composeStory = {};
}
$scope.closePopup = function(){
$scope.popupVisible = false;
}
$scope.composeStory = {};
$scope.sentCompose = [];
$scope.sendStory = function() {
$scope.sentCompose.push($scope.composeStory);
$scope.popupVisible = false;
$http.post("insert.php", data).success(function(data, status, headers, config){
});
};
我想将此表单中的数据保存到数据库中吗?Thx提前
首先,您应该能够在mysql中创建一个数据库并为此创建一个表
然后您应该能够将它们与php连接起来,如下所示:
$host = "localhost";
$user = "angular";
$pass = "angular";
$database = "angular";
$con = mysql_connect($host,$user,$pass);
if (!$con) {
die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
mysql_select_db($database,$con);
由于您提供的信息有限,我将尽力帮助您。当你提出问题时,请展示你得到了什么输出,你的调试说明了什么。这将有助于其他人理解你的问题,并为你提出一些解决方案。以下是我的建议
1) 我看不到您的$http.post("insert.php", **data**)
数据变量的范围,请确保您在其中序列化了数据。
2) 检查firebug是否发送了您的请求。如果你能看到请求,那么看看你得到的是什么响应
3) 由于成功处理程序总是为任何Ajax调用提供一个错误处理程序,因此这是一种最佳做法,可以节省调试的大量时间
我的建议是基于这样一种假设,即您的insert.php
经过了正确插入数据的测试。如果没有,你必须遵循John Conde告诉的