Skip to content

Instantly share code, notes, and snippets.

@cloudrain21
Created April 18, 2016 21:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cloudrain21/382d11169747541e12f760d479d66525 to your computer and use it in GitHub Desktop.
Save cloudrain21/382d11169747541e12f760d479d66525 to your computer and use it in GitHub Desktop.
Ajax client and nodejs express server exchange json and text data
// ajax client
$(".download-selected-list").click( function() {
$.ajax( {
type: "post",
url:'http://localhost:3000/ajax-mongo/downloadImagesZip',
contentType: 'application/json', // to server
data: JSON.stringify({"arr":arrSelectedSrc}),
dataType: 'text', // from server
// dataType: 'binary', // from server
success: function(recvdata) {
console.log("download zip...");
},
error: function(req,status,error) {
console.log("code:"+req.status+"\n"+"message:"+req.responseText+"\n"+"error:"+error);
}
});
});
// node express server
router.post('/downloadImagesZip', function(req, res, next) {
var urlArr = req.body.arr;
console.log("length : " + urlArr.length);
for(var i=0; i<urlArr.length; i++) {
console.log(urlArr[i]);
}
res.end( "This is zip data" );
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment