0
我已經使用節點Js啓動POST服務器。我想通過html文件訪問POST服務。如何在html文件中插入節點js腳本
<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>
這是行不通的。但是iF我在節點js中獨立運行腳本,我得到的帖子回覆
節點代碼並不意味着在客戶端運行。它的服務器端(後端) – monssef