0
ノードJを使用してPOSTサーバーを開始しました。 POSTサービスにhtmlファイルでアクセスしたい。ノードjsスクリプトをhtmlファイルに挿入する方法
<html>
<body>
<script type="text/javascript">
function PostMethod(){
var http = require('http');
//The url we want is: 'www.random.org/integers/?num=1&min=1&max=10&col=1&base=10&format=plain&rnd=new'
var options = {
host: 'localhost',
port:8081,
path: '/',
method: 'POST'
};
callback = function(response) {
var str = '';
//another chunk of data has been recieved, so append it to `str`
response.on('data', function (chunk) {
str += chunk;
});
//the whole response has been recieved, so we just print it out here
response.on('end', function() {
alert(str);
});
}
http.request(options, callback).end();
}
</script>
<form>
Enter No:<input type="text" id="number" name="number"/><br/>
<input type="button" value="click" onclick="PostMethod()"/>
</form>
</body>
</html>
これは機能しません。しかし、私はノードjでスクリプトを別々に実行しています。私が受け取った投稿の返信
ノードコードはクライアント側で実行されるものではありません。そのサーバー側(バックエンド) – monssef