我正在使用一個angularjs前端和nodejs作爲後端,我很困惑爲什麼我的callobj
沒有按預期工作。Nodejs全局對象沒有更新
我的相關的NodeJS代碼是:
VAR客戶=要求( 'twilio')(accountSid,的authToken);
var unirest = require('unirest');
var express = require("express");
var http = require('http');
var app = express();
var o2x = require('object-to-xml');
var qs = require('querystring');
app.use(express.static('dist'));
app.get("/", function (req,res) {
res.render('index.html');
});
var callobj = {};
app.post("/call", function(req,res){
callobj.user = req.user;
callobj.phone = req.phone;
callobj.song = req.song;
callobj.mp3link = req.mp3link;
console.log(req.body);
console.log(callobj);
res.send(200);
});
app.get("/call", function(req,res) {
console.log(callobj);
res.set("Content-Type", "text/xml");
res.send(o2x({
'?xml version="1.0" encoding="utf-8"?' : null,
Response: {
Play: callobj.mp3link
}
}));
});
的angularjs代碼:
var app = angular.module('angularexpressApp', []);
app.controller('appController', function($scope, $http){
$scope.user = 'Shawn';
$scope.phone = '5197227689'
$scope.song = 'Cant feel my face';
$scope.mp3link = 'https://api.twilio.com/cowbell.mp3';
$scope.mp3submit = function(){
$http.post('/call', {user: $scope.user, phone: $scope.phone, song: $scope.song, mp3link: $scope.mp3link})
.success(function(data){
//what to do here
})
.error(function(data){
console.log('Error: ' + data);
});
};
});
問題是什麼? – SLaks
雅問題不是跟全局對象有關,犯了一個錯誤對不起! – Shawn123