0
var request = require('request');
request.get('https://r2d2-secret-pass.herokuapp.com/validate', function(err, resp, body){
console.log(body);
});
function CheckPassword(password){
var psw = /^[a-zA-Z0-9-]\w{1,6}$/;
if (password.value.match(psw)){
alert('Senha válida, redirecionando ..');
document.location.assign(body);
return false;
}
else{
alert('Senha inválida. Tente novamente.');
return true;
}
}
I’m a beginner in Javascript and need to use the 'body' of the first function in the 'Document.location.assign' of the second, some tip on how to do ?
Try the following: before the request, put
var body;
.... and within the request putbody = body;
– Sam
@Sam returns me Undefined, even inside the 'body' I have a link to a youtube video
– Matheus Rondow
The request is asynchronous (AJAX). So the body variable does not yet exist in the function.
– Sam