Я пытаюсь вычислить BMI с помощью JavaScript (Clienside) и Node.js (Serverside).Не могу получить ответ от Node.js
Если я называю URL узла и передать параметры я получаю ответ, , но если я называю URL узла с xhr
я не получаю responseText
.
Я получаю код состояния 200, но не responseText
.
Где проблема? Спасибо за вашу помощь!
Node.js
var express = require('express');
var bodyParser = require('body-parser');
var app = express();
app.get('/bmi', function(req, res){
var bmi = req.query.weight/(req.query.height * req.query.height);
var msg = 'Hallo '+req.query.name+', deine BMI ist ' + bmi;
res.send(msg);
console.log(msg);
}).listen(80);
Javascript
function bmi(){
var response;
var name = document.getElementById("name-input").value;
var weight = document.getElementById("weight-input").value;
var height = document.getElementById("height-input").value;
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function(){
//console.log(xhr.readyState);
if(xhr.readyState === 4 && xhr.status === 200){
response = xhr.responseText;
document.getElementById("response").innerText = response;
}
//console.log(xhr.responseText);
};
xhr.open("GET", "http://localhost/bmi?name="+name+"&height="+height+"&weight="+weight, true);
xhr.send();
}
Я пытался тонны свободных портов. Вы редактируете запрос js, как? –
Убедитесь, что ваши переменные установлены: 'xhr.open (" GET "," http: // localhost: 8080/bmi? Name = "+ name +" & height = "+ height +" & weight = "+ weight, true) ; xhr.send(); ' –
Я использую Comodo Internetsecurity, мне нужно сделать некоторые варианты брандмауэра для Node.js, может быть? –