2016-06-15 19 views
0

nodejsに問題があります。誰かが私を助けてくれるかどうか確認してください。url-nodejsのパラメータを渡す

私は私が私が空白のページに取られています、それを送信するとき、私は、それを送信することはできませんよ

page.html?s=1 

のような値でのparamを渡す必要がするpage.htmlを持っています。

server.js次のようになります。

var app = require('http'); 
var fs = require('fs'); 
var path = require('path'); 
var url = require('url') ; 

var http = app.createServer(function handler(request, response) { 

var filePath = '.' + request.url; 
if (filePath == './') 
    filePath = './index.html'; 

var extname = path.extname(filePath); 
var contentType = 'text/html'; 
switch (extname) { 
    case '.js': 
     contentType = 'text/javascript'; 
     break; 
    case '.css': 
     contentType = 'text/css'; 
     break; 
    case '.json': 
     contentType = 'application/json'; 
     break; 
    case '.png': 
     contentType = 'image/png'; 
     break; 
    case '.jpg': 
     contentType = 'image/jpg'; 
     break; 
    case '.wav': 
     contentType = 'audio/wav'; 
     break; 
    case '.xml': 
     contentType = 'text/xml'; 
     break; 
} 

fs.readFile(filePath, function (error, content) { 
    if (error) { 
     if (error.code == 'ENOENT') { 
      fs.readFile('./404.html', function (error, content) { 
       response.writeHead(200, {'Content-Type': contentType}); 
       response.end(content, 'utf-8'); 
      }); 
     } 
     else { 
      response.writeHead(500); 
      response.end('Sorry, check with the site admin for error: ' + error.code + ' ..\n'); 
      response.end(); 
     } 
    } 
    else { 
     response.writeHead(200, {'Content-Type': contentType}); 
     response.end(content, 'utf-8'); 
    } 
}); 

}).listen(3100); 
console.log('Server started at 3100'); 

は、あなたがより多くの情報が必要なら、私に教えてください。

+0

そして、HTTP/200は、リターンコードは...ですか?たぶんサーバーからのログでしょうか?質問パーツs = 1とファイル名(私はnode.jsの開業医ではありません、ごめんなさい)に "filename?s = 1"を分割します。 – Dilettant

答えて

0

url parameterがどうなるかは、クエリ文字列と呼ばれていること、page.html/:something

+0

試してみました。あなたはあなたの答えをサポートするいくつかのリンクを提供できますか? –