我正在尝试使用vanilla javascript来表达服务器的get请求,但是我被困在接收快递js中的请求(我的终端在我的get请求调用中没有打印任何内容)。 我错过了我的快递根本不听取我的请求的事情吗?
前端:
(function () {
var retrieve = document.getElementById('retrieve'),
results = document.getElementById('results');
retrieve.addEventListener('click', function (e) {
var oReq = new XMLHttpRequest();
console.log('GET', e.target.dataset.url);
oReq.open('GET', e.target.dataset.url, true);
oReq.onload = function () {
console.log('Inside the onload event');
if(oReq.readyState === 4){
if(oReq.status === 200){
console.log(oReq.reponseText, "pass");
}
else{
console.error(oReq.statusText);
}
}
};
oReq.onerror = function(e){
console.error(oReq.statusText, "error");
}
oReq.send(null);
});
}());
<h1>Vanilla Ajax without jQuery</h1>
<button id="retrieve" data-url="/">Retrieve</button>
<p id="results"></p>
var express = require('express');
var path = require("path");
var bodyParser = require('body-parser');
var morgan = require('morgan');
var db = require('./db');
var cors = require("cors");
var app = express();
app.use(cors());
app.use(bodyParser.json());
app.use('/', express.static(path.join(__dirname, '../client')));
app.get("/", function(req,res){
console.log("get");
});
app.listen(3000, function () {
console.log('Example app listening on port 3000!')
})