Send blob from .js file to php with ajax
This question already has an answer here:
JavaScript is not the best language, at the moment, to work with binary data. It is being improved widely, but only on modern browsers (most notably, only IE10+ and mobile support is sometimes partial).
Thus said, with XHR2 (browser support) you can send binary data. Using XHR2 is really easy, and you can read a very nice article here: http://www.html5rocks.com/en/tutorials/file/xhr2/ . If you really need to use jQuery for managing async requests, then you need to use FormData and the tricks explained here: https://stackoverflow.com/a/13333478/192024
PS: be careful with storing blob data into MySQL databases, as sometimes there can be issues, especially with large files!
你可以尝试这样的事情。
var data;
var blob = new Blob(["i am a blob"]);
var reader = new FileReader();
reader.onloadend = function () {
data = reader.result;
$.ajax({
type: 'POST',
url: 'test.php',
data: {roll: data},
});
}
reader.readAsDataURL(blob);
链接地址: http://www.djcxy.com/p/19624.html
上一篇: AJAX JQuery上传图片