从图像标签<img>使用jquery调用POST服务
save image from image tag <img> using POST service call using jquery
我试图从图像标签中保存图像
我已经尝试过像文件上传方法
但它不工作,
var request = new XMLHttpRequest();
var imageUrl = info.ImageUri + '/Upload?imagePath=' + imagePath + '&imageName=' + imagename + '&imageSize=' + imagesize;
var imageFileUri;
request.open('POST', imageUrl);
request.send(imgFile.files[0]);
request.onreadystatechange = function () {
if (request.readyState == 4) {
if (request.status == 200) {
是否有任何方法来保存已经在图像标签中显示的图像?
您可以从图像中获取base64字符串。
html:<img src="http://some/image/source" id="myImage"/>
<canvas id="myCanvas" style="display:none;"/>
js:
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
var img = document.getElementById("myImage");
ctx.drawImage(img, 10, 10);
var imgString = c.toDataURL();
$.ajax({
type: "POST",
dataType: "JSON",
data: {
imageString: imgString
}
url: "/route/to/store/my/image",
success: function (data) {
alert('success');
}
});
和在服务器端从base64字符串生成图像,并将其与文件名一起存储。:)
这段代码是我以前写的jquery UI插件的一部分。需要jquery,
var self=this;
if(!self._chMaxSize(self)){
dialogMsg("Max file is " + self.maxMb + "Mb", "Error", null);
return;
}
var msg="";
$.each(self.savingFiles, function(index, file) {
msg+="<br>Sending... " + file.name + " ";
var fd = new FormData();
fd.append("file", file);
fd.append("idRef", idRef);
$.ajax({
xhr: function() {
var xhr = new window.XMLHttpRequest();
xhr.upload.addEventListener("progress", function(evt) {
if (evt.lengthComputable) {
var percentComplete = evt.loaded / evt.total;
percentComplete = parseInt(percentComplete * 100);
$("#msg").html(msg +percentComplete + "%");
}
}, false);
return xhr;
},
type: 'POST',
url: 'fileUpload.htm',
data: fd,
cache: false,
contentType: false,
processData: false,
success: function (data) {
msg+="<br> "+ data.result.msg;
$("#msg").html(msg);
$("#msg").addClass("ui-state-highlight");
}, error: function(data){
$("#msg").html("Transfer File Error.");
$("#msg").addClass("ui-state-error");
}
});
});
相关文章:
- 在服务工作者中导入jquery.js
- 纯Jquery Web服务响应
- 必须等待执行 jQuery,直到加载服务
- 如何在javascript或jquery中调用 asp.net 基于3.5 soap xml的Web服务
- 使用Jquery ajax将数据发送到服务
- 从javascript或Jquery调用Web服务
- JQuery-HTML到PDF没有'无法在IE中工作(来自C#asmx Web服务)
- 如何将用户从jquery移动窗体键入的查询SQL发布到WCF服务,并在WCF服务上运行该查询
- JQuery不加载通过服务获得的效果
- jQuery验证,在继续之前等待服务调用响应
- 如何使用Javascript/jQuery将GET值从URL从PAGE1传输到JSON Web服务
- 从jquery调用REST服务
- 从jQuery调用Web服务失败适用于python
- jQuery.ajax 从 wcf 服务和显示中获取图像
- 通过服务链接到 jQuery 按钮
- 多个链式 jQuery AJAX POST Web 服务调用
- 从客户端网站使用 ajax/jquery 将参数传递给 Web 服务方法
- 如何在 JQuery Ajax 中解析 Web 服务 url
- 如何通过jquery从Soap服务获取数据
- 添加复选框到数据表JQuery服务端