Skip to content

Instantly share code, notes, and snippets.

@saumya
Created May 20, 2014 20:03
Show Gist options
  • Save saumya/402d2f035b23d7d08877 to your computer and use it in GitHub Desktop.
Save saumya/402d2f035b23d7d08877 to your computer and use it in GitHub Desktop.
//
var express = require('express');
var app = express();
app.all('*', function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "X-Requested-With");
next();
});
app.get('/', function(req, res){
res.send('Hello World');
});
app.get('/myTestAPI', function(req, res){
var a = (req.query.argOne);//getting param from the request
var b = (req.query.argTwo);
var resultOBJ = {'responseText':'this is success','someMoreData':'Extra data'};
res.send(resultOBJ);
});
var server = app.listen(3001, function() {
console.log('Listening on port %d', server.address().port);
});
@saumya
Copy link
Author

saumya commented May 20, 2014

//call from frontend
$.ajax({
url: reqURI,
type: "GET",
cache: false,
data: { 'argOne':'First Data', 'argTwo':'more Data'},
dataType: "json",
success: function(result) {
console.log(result);
},
error: function(error) {
console.log('AJAX : ERROR : Problem With server ');
console.log(error);
}
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment