1

I wanted to send array to server and do check in nodejs code

function(project id){// Project id = [1,3,4,5] 
     var data : project id
     $.ajax({
        type:'POST',
         url: '/checkstatus',
         data: data,
    }).function(done){
         console.log(true);
    }
}

// Could you please correct the Ajax code and as well as how do you get input in req in server side. i want to run loop in server side.

1
  • 2
    Hey @kundan, this is the very common problem, probably you can follow some online tutorial to get it done. Commented Aug 30, 2018 at 10:31

1 Answer 1

2

You can achived this like this:

function(project id){// Project id = [1,3,4,5] 
     var data : project id
     $.ajax({
        type:'POST',
         url: '/checkstatus',
         data: JSON.stringify(data),//it will convert array to string
    }).function(done){
         console.log(true);
    }
}

And server side convert string to array like this.

let data = JSON.parse(req.body)
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks a lot Narayan Sharma, could you please help me to write code in server side. i wanted to check jenkins Api wheather job is created or not for all project id. and get output in array or object for display in table in ui
exports.checkjob = function (req, res) { var data = req.body) // req.body { ' "1","3","4", 5" ': ' ' } logger.debug(req.body); jenkins.view.exists(pipelineName, function (err, exists) { if (err) { res.send({ error: true, message: err.message }); } res.send({ error: false, message: exists }); }); };
if you print that it will give you an array so loop through that array and do what ever you want to. If this helpful for you please mark this answer as correct. So that it will helpful for other too.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.