Vitthal Kamkar
Vitthal Kamkar

Reputation: 21

how to extract URL parameter from POST request in nodejs and expressjs

REQUEST URL http://localhost:9090/rest-api/fetchDetailedProductInfo?prodId=1&tempId=123

fetchDetailedProductInfo: function (prodId) {                                      
    var self = this;
    var URL = 'http://localhost:9090/rest-api/fetchDetailedProductInfo'
    $.ajax({                                               
        url: URL,
        dataType: 'json',
        contentType:'json',
        type:'GET',
        data: {
            'prodId':prodId,
            'tempId':123
        },                       
        success:function(responce) {
            self.renderUI(responce.json);
        },
        error: function (err) {
            console.log('ERROR',err)
        }
    });                    
},

@ SERVER SIDE

router.get('/rest-api/fetchDetailedProductInfo', function (req, res) {  
    var prodId = req.param('prodId');
    var tempId = req.param('tempId');
    res.send(prodId + '----' + tempId);
}

Upvotes: 0

Views: 1307

Answers (1)

user1481317
user1481317

Reputation:

I think you confused with req.params and req.query. Here is link to another question

Use req.query

 var prodId = req.query.prodId;
 var tempId = req.query.tempId;

Please see this

Upvotes: 1

Related Questions