Node.js의 서버에 웹의 자바 스크립트 코드에서 간단한 연결 (요청 - 응답)을 보내려고합니다. 이 방법은 만들기 ggeeett 요청 것을 내가 검색 계속 내가 FireBugNodeJS에 자바 스크립트로 GET 요청
에 오류가있어이 코드를 실행
var request = new XMLHttpRequest();
request.open('GET', 'http://localhost:4444/', false);
request.send();
if (request.status === 200) {
console.log(request.responseText);
}
내가 발견
나는 follows로 요청을 만들기 위해 노력했다 동일한 도메인에 있습니다. 도메인 간 요청을하려면 다른 전략을 사용해야합니다.
은 내가 jQuery method을 발견하고, 내가 올바른 방법에있어 보인다 :$.get(
'http://localhost:4444/',
function(data) {
alert("sucess");
//Do anything with "data"
}
);
을 내가 동일한 응답 without the error를 얻을이 경우.
작동하는 것처럼 보이지만 "경고"메시지가 표시되지 않습니다! 무슨 일이야? 내가 도대체 뭘 잘못하고있는 겁니까?
Node.js를 서버 코드는 다음과 같습니다
var http = require("http");
http.createServer(function(request, response) {
response.writeHead(200, {"Content-Type": "text/html"});
response.write("Response");
response.end();
}).listen(4444);