angularjs – 角json表达
发布时间:2020-12-17 17:19:54 所属栏目:安全 来源:网络整理
导读:我正在尝试使用angular.js将json发送到服务器节点/ express 我的server.js /** Setup*/// Dependenciesvar express = require('express');// Start Expressvar app = express();// Conf portvar port = process.env.PORT || 3000;/** Conf. the app*/ app.co
我正在尝试使用angular.js将json发送到服务器节点/ express
我的server.js /* * Setup */ // Dependencies var express = require('express'); // Start Express var app = express(); // Conf port var port = process.env.PORT || 3000; /* * Conf. the app */ app.configure(function () { app.use(express.static(__dirname + '/public')); app.use(express.logger('dev')); app.use(express.bodyParser()); app.use(express.methodOverride()); }); /* * Routes */ require('./app/routes')(app); /* * Listen */ app.listen(port); console.log("App listening on port " + port); 我的Routes.js module.exports = function (app) { app.post('/post/:name',function (req,res) { console.log("Serv get [OK]"); /* * Disparar broadcast para all */ }); app.get('/',res) { res.sendfile('./public/view/index.html'); }); } 当我的服务器收到POST时,我使用: app.post('/post'... OR app.get('/get'... 捕捉路线? 我的角度应用可以吗? webchatApp = angular.module("webchatApp",[]); webchatApp.controller('webchatCtrl',function ($scope,$http) { $scope.sendMsg = function () { var dados = {name:"test message"}; $http.post({url:'http://localhost/post/',data:dados}) .success(function (data) { console.log("Success" + data); }) .error(function(data) { console.log("Erro: "+data); }) }; }); 错误:无法POST / [object Object] 解决方法
尝试改为:
$http({ method: 'POST',url: 'http://localhost/post/',data: dados }) .success(function() {}) .error(function() {}); 看起来您使用了不正确的$http.post方法签名.它应该是: $http.post('http://localhost/post/',dados) .success(...) .error(...); …并且由于成功和错误方法已被弃用,因此最好是这样做 $http.post('http://localhost/post/',dados) .then(function() {...}) // success .catch(function() {...}); // error (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
推荐文章
站长推荐
- 运行码头工程师,在码头工程师gitlab-ci-multi-ru
- WebService学习总结六 WebService WSDL文档的标签
- bash:在while循环中反击(kill和kill -9)
- 如何使用Bootstrap和WITHOUT jQuery创建Angular2
- python – 在运行时将pip需求添加到docker镜像
- Dig是一个在类Unix命令行模式下查询DNS包括NS记录
- 解决报错 “build.sh /bin/bash^M: 坏的解释器:
- 在bash脚本中将HTML字符引用更改为utf-8即. ā变
- 配置 – 如何使用bdb后端配置OpenLDAP 2.4?
- Bootstrap-datetimepicker控件使用
热点阅读