1
구문 분석 할 데이터를 보내려고합니다. 클라이언트 측 스크립트는 다음과 같다 : '다음Ajax POST 요청이 익스프레스로 정의되지 않음
router.post("/create", function(req, res){
console.log(req.body);
console.log(req.body.url);
var url = req.body.url; }
나는'정의되지 않은 '얻을, 그리고 내 특급 응용 프로그램에
function addURL(link) {
console.log("Adding url...");
$.ajax({
type: "POST",
url: location.protocol + "//" + location.host + "/shorturl/create",
crossDomain: true,
contentType: "application/json",
data: JSON.stringify({url:link}),
success: function(data){
$("#shortenedURL").html(data.shortenedURL);
},
error: function(err){
console.log("Ran into an error... " + err);
}
});
}
, 라우터 중 하나에, 내가있어 정의되지 않은 속성 'URL'을 가져올 수 없습니다.
app.js :
var bodyParser = require('body-parser')
, app = express();
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: true}));
당신은 반드시 해당 URL을있는 내가 잘못거야 어디
나는 –
사용중인 expressjs 버전과 app.js 코드를 게시하십시오. –