Skip to content

Instantly share code, notes, and snippets.

@proudlygeek
Created July 17, 2012 20:48

Revisions

  1. proudlygeek revised this gist Jul 17, 2012. 4 changed files with 33 additions and 0 deletions.
    8 changes: 8 additions & 0 deletions client_cors.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,8 @@
    // http://jsfiddle.net/suBPQ/

    $.ajax({
    url: "http://api_test_server.proudlygeek.c9.io/",
    success: function(data) {
    console.log(data);
    }
    });
    File renamed without changes.
    25 changes: 25 additions & 0 deletions server_cors.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,25 @@
    // http://api_test_server.proudlygeek.c9.io/

    var http = require("http"),
    url = require("url");

    var server = http.createServer(function(req, res) {
    console.log(req.headers);

    var data = {
    'name': "Gianpiero",
    'last': "Fiorelli",
    'age': 37
    };

    res.writeHead(200, {
    'Content-Type': 'application/json',
    'Access-Control-Allow-Origin': '*'
    });

    res.end(JSON.stringify(data));
    });

    server.listen(process.env.PORT, process.env.IP);

    console.log('Server running at ' + process.env.PORT + ':' + process.env.IP);
    File renamed without changes.
  2. proudlygeek revised this gist Jul 17, 2012. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion client.js
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,6 @@
    $.ajax({
    // http://jsfiddle.net/sWaSP/​

    $.ajax({
    url: "http://api_test_server.proudlygeek.c9.io/?callback=?",
    dataType: "jsonp",
    success: function(data) {
  3. proudlygeek created this gist Jul 17, 2012.
    7 changes: 7 additions & 0 deletions client.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,7 @@
    $.ajax({
    url: "http://api_test_server.proudlygeek.c9.io/?callback=?",
    dataType: "jsonp",
    success: function(data) {
    console.log(data);
    }
    });​​​​​​​​​​​​​​​​​​
    25 changes: 25 additions & 0 deletions server.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,25 @@
    // http://api_test_server.proudlygeek.c9.io/?callback=cb

    var http = require("http"),
    url = require("url");

    var server = http.createServer(function(req, res) {

    var callback = url.parse(req.url, true).query.callback || "myCallback";
    console.log(url.parse(req.url, true).query.callback);

    var data = {
    'name': "Gianpiero",
    'last': "Fiorelli",
    'age': 37
    };

    data = callback + '(' + JSON.stringify(data) + ');';

    res.writeHead(200, {'Content-Type': 'application/json'});
    res.end(data);
    });

    server.listen(process.env.PORT, process.env.IP);

    console.log('Server running at ' + process.env.PORT + ':' + process.env.IP);