【问题标题】:cordova + angularjs + nodejs(Express) $http json always get 404cordova + angularjs + nodejs(Express) $http json 总是得到 404
【发布时间】:2015-05-23 15:18:01
【问题描述】:

我正在使用 cordova + angularjs + nodejs(Express) 在 android 环境中进行测试。现在我试图通过 $http() 获取一些数据,但我总是收到 404 错误(通过下面的警报)。

客户端代码(AngularJs)

        $http({
            method  : 'POST',
            url     : "http://192.168.1.4:8888/login",
            data    : ""
        })
        .success(function(data, status, headers, config) {
            alert("success");
            alert(data);
        })
        .error(function(data, status, headers, config) {

            alert("error");// <== always gets here
            alert(status); // <== 404
        }).
        finally(function() {
          alert("finally");
        });

服务器代码(NodeJs+Express)

...
app.get('/login',function(req, res){ 
    res.set({'Content-Type':'application/json','Encodeing':'utf8'});  
    res.json({name:"jj"}); 
}) ;
app.listen(8888); 

我可以通过 Chrome 访问 http://192.168.1.4:8888/login 来获取 json 字符串,

我搜索了很多东西,但仍然无法解决我的问题,有人可以帮忙吗?

【问题讨论】:

    标签: javascript angularjs node.js cordova express


    【解决方案1】:

    http方法是post,需要get。

    【讨论】:

    • 还有一个问题,如果我需要使用'POST'方法来提交一些数据,除了404之外还有其他方法可以让angularJS处理响应吗?
    • 它只给出了 404 响应,因为您试图针对只允许获取的 url 发帖。当 url 允许发布时,它将返回您指定返回的任何内容。
    猜你喜欢
    • 1970-01-01
    • 2016-03-10
    • 1970-01-01
    • 1970-01-01
    • 2019-05-15
    • 2017-08-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多