小编The*_*ist的帖子

AngularJS $ http.get with resolve

我开始了解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)

angularjs

8
推荐指数
1
解决办法
1万
查看次数

Handlebars 的 if 语句中的条件

我正在了解 Handlebars.js,我想向社区提出一个问题。我知道我还有很多东西需要学习,而且我正在路上,但我想看看这个问题的例子。

\n\n

在 JS 中使用对象创建的数组:

\n\n
var 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];\n
Run 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...\n
Run Code Online (Sandbox Code Playgroud)\n\n

因为对象位于数组中,所以我必须首先循环数组,{{#each}}然后有一个注册的助手(我在 github 上找到)帮助我获取密钥,因为我只想将它们写入到 head 中。

\n\n

如果没有我的 if 语句,它可以正常工作,用键填充 thead ,但是因为有 2 个对象,所以它会打印两次名称。 …

javascript handlebars.js

3
推荐指数
1
解决办法
2万
查看次数

Ajax发送数据,但php没有收到

虽然我还在阅读Nicholas C. Zakas的书(在4天内阅读了300多页),但同时我还有一个小项目,为我们后来的大项目创建一个半自动化的文档生成器页面.这已经完成了一半,但现在我想给它提供更多的功能,这需要我将textareas的值发送给PHP,因此PHP可以更新mysql而反之亦然,但现在不是问题.

问题: Ajax成功,我得到了成功消息,但PHP没有读取POST.为什么?

我做了我的研究,我阅读了stackoverflow主题和其他网站,phpmanual,w3school示例的音调,但出了点问题.

基本的HTML示例:

<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)

我找到的基本ajax调用(发送):

/* 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)

php ajax jquery post send

0
推荐指数
1
解决办法
3823
查看次数

标签 统计

ajax ×1

angularjs ×1

handlebars.js ×1

javascript ×1

jquery ×1

php ×1

post ×1

send ×1