简体   繁体   English

无法弄清楚为什么找不到角形链接

[英]Cannot figure out why the link is not being found in angular

I am sending a request 我正在发送请求

$http.get('/loadpage?category='+$scope.selectedCategory+'&page='+$scope.selectedPage).then(function(response){

    }).catch(function(){
        console.log("Error caught!");
    });

On my router.js file, 在我的router.js文件中,

I have 我有

router.get('/loadpage?category=xx&page=yy', function(req, res) {

res.send("Is this working");
});

I am not sure why my server is showing the following error. 我不确定为什么我的服务器显示以下错误。

angular.js:12587 GET http://localhost:3000/loadpage?category=1&page=1 404 (Not Found) angular.js:12587 GET http:// localhost:3000 / loadpage?category = 1&page = 1 404(未找到)

Because I tried sending a request to another url 因为我尝试将请求发送到另一个网址

router.get('/runthis/category=:xx',function(req, res){
var p = req.params.xx;

res.send(p);
});

by 通过

function runthis (){
    $http.get('runthis/category=smackthat').then(function(response){
        console.log(response.data);
    }).catch(function(){
        console.log("Error caught!");
    });
}

And it works perfectly. 而且效果很好。

Can anyone help. 谁能帮忙。 Thanks 谢谢

您正在对查询字符串(URL的?foo=bar部分)进行操作,以表示查询字符串已解析为req.query,例如req.query.foo === 'bar'因此路由应为/loadpage和您应该从req.query获取数据

Why don't you make your url a bit simpler such as : 为什么不将您的网址简化一些:

router.get('/loadpage/:category/:page', function(req, res) {
   res.send("Is this working");
});

Makes your url parameters more semantic. 使您的url参数更具语义。 and call it as : 并将其称为:

$http.get('/loadpage/'+$scope.selectedCategory+'/'+$scope.selectedPage).then(function(response){

}).catch(function(){
    console.log("Error caught!");
});

Also, when you defined your url without : in router.get('/loadpage?category=xx&page=yy'... The router is looking for an exact match for the called url, in your case, you are passing variables and unless those 2 have xx and yy in them respectively, it's working as expected and throwing 404 另外,当您在router.get('/loadpage?category=xx&page=yy'...定义不带:的url时,路由器正在寻找被调用url的完全匹配项,在这种情况下,您正在传递变量,除非那两个分别有xxyy ,它按预期方式工作并抛出404

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 用这个简单的Angular控制器无法解决问题 - Cannot figure out the issue with this simple Angular contoller 无法弄清楚为什么我的角度视图是空白的 - Can't figure out why my angular view is blank 无法找出客户端错误 - Cannot figure out Client Error 无法弄清楚为什么角度绑定在Codepen脚本中不起作用 - Can't figure out why angular binding won't work in codepen script 无法弄清楚为什么页面在底部加载? Angular UI-Router 自动滚动问题 - Can't figure out why page loads at bottom? Angular UI-Router autoscroll Issue AngularJS:无法弄清楚为什么在使用transclude:&#39;element&#39;进行转换时嵌套的角度指令不被渲染 - AngularJS : Can't figure out why nested angular directive does not get rendered when transcluding with transclude:'element' Angularjs MVC应用程序,我无法弄清楚为什么我得到一个未知的提供程序:$ routeProvider &lt;-$ route - Angularjs MVC application, I cannot figure out why I'm getting an Unknown provider: $routeProvider <- $route 无法弄清楚为什么我的角度代码不能与Ionic框架和Intel XDK一起使用 - Can't figure out why my angular code is not working with Ionic framework and Intel XDK 无法弄清楚为什么ng-view在简单的均值堆栈应用程序中不起作用 - Cannot figure out why ng-view will not work in simple mean stack app 无法弄清楚如何修改角度指令 - Unable to figure out how to modify angular directive
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM