How to pass client-side parameters to the server-side in Angular/Node.js/Express

前端 未结 4 713
孤独总比滥情好
孤独总比滥情好 2020-12-16 05:44

Probably a very basic question, but I cannot seem to find a simple answer.

I have a GET method leveraging Angular\'s $http that is requesting a promise

4条回答
  •  春和景丽
    2020-12-16 06:47

    Answer vs Good Solution

    • HTTP POST is preferred while sending data to the server.

    • HTTP GET method means querying for data, not sending data. Because of that, an HTTP request with GET method will always have request.body empty. But still data can be sent to server via GET using query string. In your case:

    Client

    $http.get('url_to_be_hit', { name : 'Mr. X'})
        .success(function(res){ //response })
        .error(function(err){ //failure });
    

    Server

    app.get('/url_to_be_hit', function(req,res,next){
       //req.query.name
    }); 
    

    Happy Helping!

提交回复
热议问题