如何在IE8中使用Ajax将图像发送到.net Webservice
How to send image to .net Webservice using Ajax in IE8?
下面的帖子是有关:如何使用Ajax发送图像到PHP文件?
我设法让这个工作按照上面的帖子,但它无法在IE8上工作。
是否有办法让这个工作在ie8+?
下面是我的代码:$("form[name='uploader']").submit(function(e) {
var formData = new FormData($(this)[0]);
$.ajax({
url: dotnetpage,
type: "POST",
data: formData,
async: false,
success: function (msg) {
$('.js-ugc-image').attr('src', msg);
},
cache: false,
contentType: false,
processData: false
});
e.preventDefault();
});
IE 8没有formdata,您可以使用隐藏的iframe并发布它并读取结果。我用了一个类似这样的技巧克隆表单,将原始表单移动到一个隐藏的iframe中(这需要这样做,因为你不能在IE上克隆或设置输入类型文件的值),然后提交并读取提交的结果。
类似这样的代码,这是我以前使用过的,并且有效:
var $form = $('your form');//GET YOUR FORM
//Create Hidden iframe
var _hiddenIframe = $('<iframe id="_hiddenframe" style="display:none;"></iframe>');
//Create Copy Form and add the attributes of the original
var _copyForm = $('<form id="_copyForm" name="_copyForm" style="">');
_copyForm.attr({'method':$form.attr('method'),'action':$form.attr('action'), 'enctype':$form.attr('enctype')});
//Get original fields
$original = $form.children('*');
//Clone and append to form
$original.clone(true).appendTo($form);
//send the original fields to hidden form
$original.appendTo(_copyForm);
//Add the iframe to the body
_hiddenIframe.appendTo('body');
//Add the form to the hidden iframe
_copyForm.appendTo(_hiddenIframe.contents().find('body'));
var $r;
//submit the form
_copyForm.submit();
//after it reloaded(after post)
_hiddenIframe.on('load',function(){
//read result (maybe a json??)
$r = $.parseJSON(_hiddenIframe.contents().find('body').text());
//Do something with the result
if($r.result=='ok'){
//Do Something if ok
}
else{
//Do Something if error
}
});
不,对不起,IE8不支持FormData对象。(见http://caniuse.com/搜索= formdata)
你可以将<input type='file >
标签嵌入到一个单独的表单中,然后使用jQuery提交。
相关文章:
- 如何使用url加载程序在webpack中导入多个图像
- nodejs-expressjs上传图像并显示它们
- 使用JSP从服务器检索和显示图像
- 角度:在ng重复上切换图像
- 画廊图像未显示
- Phonegap-(安卓/iphone)多个图像的图像库出现问题
- Javascript排序的图像弹出窗口..可以't单独弹出
- 画布数据到图像
- Windows8应用程序(html&Javascript):从图片库(除了文件选择器)显示图像的另一种方式
- 使图像在单击时展开到不大于浏览器
- Html页面上的多个Base64图像和平滑加载
- UIAutomation放大图像
- 使用javascript在Flash中加载外部图像
- 可以在这里为背景图像设置滤镜吗
- 当图像转换为本地存储的DataURL时,EXIF被删除
- 使用 js 将背景图像设置为 HTML
- Javascript将图像src更改为淡入淡出
- 如何在IE8中使用Ajax将图像发送到.net Webservice
- 如何在IE8中上传文件(图像)(javascript到webservice)-不使用FileReader api,不使用
- 如何使用文件上传通过webservice使用javascript上传图像文件到html服务器