使用angularjs获取GET和POST结果

时间:2014-10-14 04:39:14

标签: javascript node.js angularjs https

如果我正在使用angularjs并想根据是否有GET请求或POST请求来更改页面,我该怎么做?

例如:

//index.html

...
<p>{{ message }}</p>
//----------------------------------

// script.js

// create the module and name it myApp
    // also include ngRoute for all our routing needs
var myApp = angular.module('myApp', ['ngRoute']);

// configure our routes
myApp.config(function($routeProvider) {
    $routeProvider

        // route for the home page
        .when('/', {
            templateUrl : 'pages/home.html',
            controller  : 'mainController'
        })

        // route for the about page
        .when('/about', {
            templateUrl : 'pages/about.html',
            controller  : 'aboutController'
        })

        // route for the contact page
        .when('/contact', {
            templateUrl : 'pages/contact.html',
            controller  : 'contactController'
        });
});

// create the controller and inject Angular's $scope
myApp.controller('mainController', function($scope) {
    // create a message to display in our view
    $scope.message = 'Everyone come and see how good I look!';
});

myApp.controller('aboutController', function($scope) {
    $scope.message = 'Look! I am an about page.';
});

myApp.controller('contactController', function($scope) {
    $scope.message = 'Contact us! JK. This is just a demo.';
});

现在,我了解在向GET home.html发出https请求时会呈现mysite.com/#/

如果为home.html触发https POST请求,我如何以不同方式呈现和填充mysite.com/#/? 例如,页面mysite.com/#/上有一个“提交”按钮。

谢谢, ķ

0 个答案:

没有答案