Bootstrap

ajax后端怎么接受信息,ajax nodejs 前后端发送接收消息并回应

刚刚接触nodejs ,最近想实现前后端的通信,不知道为啥实现不了。代码如下

ajax:

var sending = function() {

var xmlhttp;

if (window.XMLHttpRequest) {

xmlhttp = new XMLHttpRequest();

}

xmlhttp.onreadystatechange = function() {

if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {

document.getElementById("show").innerHTML = xmlhttp.responseText;

} else {

document.getElementById("show").innerHTML = xmlhttp.readyState;

document.getElementById("show").innerHTML += ' ' + xmlhttp.status;

}

}

xmlhttp.open("PSOT", "127.0.0.1", true);

xmlhttp.send("lalal");

nodejs:

var http = require("http");

var querystring = require("querystring");

http.createServer(function(req, res) {

res.writeHead(200, { 'Content-Type': 'text/plain' });

res.end('hello world');

}).listen(8080, '127.0.0.1');

console.log("running");

求教大神为何实现不了啊?另外这是chrome显示的错误信息

Uncaught DOMException: Failed to execute 'open' on 'XMLHttpRequest': Invalid URL

;