Created
April 18, 2016 21:07
-
-
Save cloudrain21/382d11169747541e12f760d479d66525 to your computer and use it in GitHub Desktop.
Ajax client and nodejs express server exchange json and text data
This file contains 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
// 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