mirror of
https://github.com/tenrok/axios.git
synced 2026-06-17 19:21:29 +03:00
Improving examples
This commit is contained in:
@@ -9,11 +9,7 @@
|
||||
|
||||
<form role="form" class="form" onsubmit="return false;">
|
||||
<div class="form-group">
|
||||
<label for="url">URL</label>
|
||||
<input id="url" type="text" class="form-control"/>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="data">Body</label>
|
||||
<label for="data">JSON</label>
|
||||
<textarea id="data" class="form-control" rows="5"></textarea>
|
||||
</div>
|
||||
<button id="post" type="button" class="btn btn-primary">POST</button>
|
||||
@@ -21,15 +17,14 @@
|
||||
|
||||
<div id="output" class="container"></div>
|
||||
|
||||
<script src="/dist/axios.min.js"></script>
|
||||
<script src="/axios.min.js"></script>
|
||||
<script>
|
||||
(function () {
|
||||
var output = document.getElementById('output');
|
||||
document.getElementById('post').onclick = function () {
|
||||
var url = document.getElementById('url').value;
|
||||
var data = document.getElementById('data').value;
|
||||
|
||||
axios.post(url, JSON.parse(data))
|
||||
axios.post('/post/server', JSON.parse(data))
|
||||
.then(function (res) {
|
||||
output.className = 'container';
|
||||
output.innerHTML = res.data;
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
module.exports = function (req, res) {
|
||||
var data = '';
|
||||
|
||||
req.on('data', function (chunk) {
|
||||
data += chunk;
|
||||
});
|
||||
|
||||
req.on('end', function () {
|
||||
console.log('POST data received');
|
||||
res.writeHead(200, {
|
||||
'Content-Type': 'text/json'
|
||||
});
|
||||
res.write(JSON.stringify(data));
|
||||
res.end();
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user