Monday 12 June 2017

how to handle NodeJS query response using javascript

router.post('/queryrule', function(req, res){
var requestID = req.body;

var frm_requestID = requestID['sbruleid'];
req.checkParams('frm_requestID', 'Not valid Rule ID!').isInt();

var errors = req.validationErrors();
if(errors){
        res.render('queryrule',{
                errors:errors
        });
} else {
  var query = { sbruleid: frm_requestID };
    Ids.searchids(query, function (err, id) {
            if (err) throw err;
            console.log("out: "+ id); //-> the id json query is correct
            res.send(ids); //-> this suppose to send data on my javascript
    });
}}); 

Hi thanks for reading and answering. I do not receive any data after my node js res.send data to my javascript.I have this nodejs query code and works fine until console.log("out: "+ ids), and below is the javascript that post the data and suppose to received the response but its not working.

$(document).ready( function() {
$('#btn_frm_search').click( function() {

    query = { 'success' : false, 'data' : "" };

    query = validateFilter();
    if ( !query.success ) {
        return false;
    }

    quertdata = query.data;
//alert("filter:  "+ quertdata['sbruleid']);
    $.post( '/users/queryidsrule' , quertdata , function(data) {
        console.log(data); // -> this suppose to receive data from nodejs but no data receive.
        createResultTable(data);
    });
});

});



via mr yhel

No comments:

Post a Comment