Created
November 25, 2012 03:55
-
-
Save airportyh/4142335 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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