Angular $ http服务不调用快速路由

时间:2016-08-28 05:39:08

标签: javascript angularjs express

这是我尝试将http get请求发送到本地服务器的角度方法

  $scope.getMeth = function(){
            // Simple GET request example:
    $http({
      method: 'GET',
      url: 'http://127.0.0.1:9876/'
    }).then(function successCallback(response) {
      // this callback will be called asynchronously
      // when the response is available
      $scope.serverResponse = response.status;
    }, function errorCallback(response) {
      // called asynchronously if an error occurs
      // or server returns response with an error status.
      //console.log(response);
      $scope.serverResponse = response.status;
    });

这是使用express

的服务器代码
var http = require('http');
var fs = require('fs');
var express = require('express');
var app = express();

app.get('/', function(req, res) {
    if (req) {
        console.log(req.url);
        res.send('hello');
    } else {
        console.log('waiting');
    }

});

app.listen(9876, function() {
    console.log('Example app listening on port 9876!');
});

我总是得到错误响应和-1状态代码,这里有什么问题?

0 个答案:

没有答案