익스프레스 서버와 jquery를 클라이언트 측에서 사용했습니다. jquery post 메서드를 통해 서버에 게시물 요청을 보내지 만 서버에 등록되지 않습니다.익스프레스가 jquery 포스트 요청을 수신하지 않음
가 여기에 해당 서버 코드입니다 :
var express=require("express");
var path=require("path");
var bodyParser=require("body-parser");
var app=express();
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ // to support URL-encoded bodies
extended: true
}));
app.post("/tru",function(req,res){
console.log("Ok done"); //This never gets logged.
console.log(req.body.messag);
});
그리고 여기에 클라이언트 코드입니다 :
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
<form id="sef"><input id="ae" placeholder="Enter Something"></form>
</script>
<script type="text/javascript">
$(document).ready(function(){
$("#sef").submit(function(){
$.post("localhost:3000/tru",{messag:$("#ae").val()});
});
});
</script>
그래서, 무슨 일입니다 전자 오류?
수정 - 문제가 해결되었습니다.
se=$("#ae").val();
$.post("/tru",{messag:se});
은 분명히, JQuery와 localhost를 인식하지 않습니다 그냥 $ 포스트 방법을 변경합니다.
도움 주셔서 감사합니다.
에서 수신하도록 서버를 설정 했습니까. (...'또한 – Ananth
'$의 .post를 "제출"에 ("/ " – Ananth
네, 맞아요. –