Skip to content

Instantly share code, notes, and snippets.

@airportyh
Created November 25, 2012 03:55
Show Gist options
  • Select an option

  • Save airportyh/4142335 to your computer and use it in GitHub Desktop.

Select an option

Save airportyh/4142335 to your computer and use it in GitHub Desktop.
<!doctype html>
<html>
<head>
<title>Test Page</title>
<script src="jquery.js"></script>
<script>
$(function(){
$.ajax({
url: '/api',
success: function(data){
console.log(data)
$.post('/api', {num: Number(data) + 1})
}
})
})
</script>
</head>
<body>
<h1>Test Page</h1>
</body>
</html>
var express = require('express')
var app = express()
app.use(express.bodyParser())
app.get('/', function(req, resp){
resp.sendfile('index.html')
})
app.get('/jquery.js', function(req, resp){
resp.sendfile('jquery.js')
})
app.get('/api', function(req, resp){
var num = Math.round(Math.random() * 10)
console.log('GET /api ' + num)
resp.end(String(num))
})
app.post('/api', function(req, resp){
var num = req.body['num']
console.log('POST /api ' + num)
resp.end('')
})
app.listen(7357)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment