javascript - Ajax requests the nodejs background. After starting the server, the localhost:3000/index.html page neither reports an error nor has text. . .
某草草
某草草 2017-05-24 11:38:49
0
1
733
The code of

index.html is (there are two input boxes and a button on the page):

$("input[type=button]").on("click",function() {
        if ( $username=="" || $password=="" ) {
            alert("请输入完整!");
        } else {
            $.ajax({
                type: "POST",
                url: "http://localhost:3000",
                data: {
                    user: $username,
                    pwd: $password
                },
                success: function(data) {
                    var data=JSON.parse(data);
                    console.log(data);
                },
                error: function() {
                    alert("出错啦!");
                }
            })
        }
    })

The code of server.js is:

var http=require('http');
var querystring=require('querystring');

http.createServer(function(req, res) {
    var data="";

    req.on("data", function(chunk) {
        data+=chunk;
    })
    req.on("end", function() {
        data=querystring.stringify(data);
        res.end(data);
    })

}).listen(3000, function() {
    console.log("Starting to listen on port 3000");
})

After starting the server, there is nothing on the page and the article is blank. . . Heartbreaking

某草草
某草草

reply all(1)
迷茫

The information on your server side is wrong

  • Understand the principles of webserver

  • Take a look at this simple example and see if you know how to change it
    https://github.com/cristismf/...

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!