我开始了解AngularJS,我有一个有趣的问题.我开始了解routeProvider,我想我可以编写我的应用程序,就像你搜索一个表名一样,它会改变路由,所以你也可以在url之后写表.
来自app.js的详细信息
app.config(function($routeProvider){
$routeProvider
.when('/', {
templateUrl: 'pages/index.html',
controller: 'homeCtrl'
})
.when('/tables/:table', {
templateUrl: 'pages/about.html',
controller: 'aboutCtrl',
resolve: {
tables: function($http, $routeParams){
return $http.get('http://mywebsite.com/doc/ajax/table.php?function=get_table_data&table='+$routeParams.table)
.then(function(response){
console.log($routeParams.table);
return response.data;
})
}
}
})
.otherwise({
templateUrl: 'pages/404.html'
})
});
Run Code Online (Sandbox Code Playgroud)
控制器
angular
.module('testApp')
.controller('aboutCtrl',function($scope, tables){
$scope.title = "This is the about page!";
// declare helper variables to not use
// $scope inside a loop
var rawFields = [];
var titleNames = [];
// load the thead titles (keys)
angular.forEach(tables[1], function(value, key){
titleNames.push(key);
}); …Run Code Online (Sandbox Code Playgroud) 我正在了解 Handlebars.js,我想向社区提出一个问题。我知道我还有很多东西需要学习,而且我正在路上,但我想看看这个问题的例子。
\n\n在 JS 中使用对象创建的数组:
\n\nvar data = \n[\n{\n Field: "id",\n Type: "int(11)",\n Null: "NO",\n Key: "PRI",\n Default: null,\n Extra: "auto_increment"\n},\n{\n Field: "id2",\n Type: "int(131)",\n Null: "N3O",\n Key: "PR3I",\n Default: null,\n Extra: "auto_increment"\n}\n];\nRun Code Online (Sandbox Code Playgroud)\n\n格式是这样的,因为我从服务器收到的 JSON 看起来就像是这样,但现在为了测试我不想进行 ajax 调用。
\n\n模板:
\n\n<table>\n <thead>\n <tr>\n\n {{#each this}}\n {{#only_once this}}\n {{#key_value this}}\n <th>{{key}}</th> \n {{/key_value }}\n {{/only_once}}\n {{/each}}\n\n </tr> \n </thead>\n...\nRun Code Online (Sandbox Code Playgroud)\n\n因为对象位于数组中,所以我必须首先循环数组,{{#each}}然后有一个注册的助手(我在 github 上找到)帮助我获取密钥,因为我只想将它们写入到 head 中。
如果没有我的 if 语句,它可以正常工作,用键填充 thead ,但是因为有 2 个对象,所以它会打印两次名称。 …
虽然我还在阅读Nicholas C. Zakas的书(在4天内阅读了300多页),但同时我还有一个小项目,为我们后来的大项目创建一个半自动化的文档生成器页面.这已经完成了一半,但现在我想给它提供更多的功能,这需要我将textareas的值发送给PHP,因此PHP可以更新mysql而反之亦然,但现在不是问题.
问题: Ajax成功,我得到了成功消息,但PHP没有读取POST.为什么?
我做了我的研究,我阅读了stackoverflow主题和其他网站,phpmanual,w3school示例的音调,但出了点问题.
<form id="foo">
<label for="bar">A bar</label>
<input id="bar" name="bar" type="text" value="" />
<input type="submit" value="Send" />
</form>
<div id="result"></div>
<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<script src="script.js"></script>
Run Code Online (Sandbox Code Playgroud)
/* Attach a submit handler to the form */
$("#foo").submit(function(event) {
/* Stop form from submitting normally */
event.preventDefault();
/* Clear result div*/
$("#result").html('');
/* Get some values from elements on the page: */
var values = $("#foo").serialize();
console.log("val: "+values);
/* Send the data using post and put the results …Run Code Online (Sandbox Code Playgroud)