简体   繁体   English

jQuery表单插件在IE中不起作用

[英]jQuery form plugin doesn't work in IE

I'm using jQuery form plugin to upload files via ajax. 我正在使用jQuery表单插件通过ajax上传文件。 I've tested the scripts and it works in all browsers except IE.It seems that in IE nothing happens(events & ...). 我已经测试了脚本,并且可以在除IE之外的所有浏览器中使用。似乎在IE中什么也没有发生(事件&...)。 I'm working for hours, still no luck. 我工作了几个小时,仍然没有运气。

PHP: PHP:

echo $this->input->post('name');//this is a debuging statement which shows the data sent by client

JS: JS:

$("input[type=file]").on('change',function(){
    $(this).parents('.fileinput-wrapper').find('.fileinput-preview').css('background','url(http://localhost/project/assets/images/ajax-loader.GIF) no-repeat center center');
    var selectedElement = this;
    var name = $(this).attr('name').toString();
    $('#upload').ajaxSubmit({
        //dataType:'json',
        data: {name:name},
        success: function(data) {
            $(selectedElement).parents('.fileinput-wrapper').find('.fileinput-preview').css('background',"url('http://localhost/project/assets/images/loading.png') no-repeat center center");
            return false;
        },
        error : function(xhr) {
            alert(xhr.responseText);
            return false;
        }
    });
});

What should I do? 我该怎么办? (Thanks for help.) (感谢帮助。)

Internet Explorer 9 and below doesn't support the XMLHttpRequest Level 2 protocol. Internet Explorer 9及更低版本不支持XMLHttpRequest Level 2协议。 This is required by jQuery to upload files asynchronously. jQuery要求以异步方式上传文件。 You'll have to use an iFrame or disable the upload functionality for users with legacy IE browsers. 对于使用旧版IE浏览器的用户,您必须使用iFrame或禁用上传功能。

You can use conditional comments to test for older versions of IE. 您可以使用条件注释来测试IE的较早版本。 Add the following to your JavaScript: 将以下内容添加到您的JavaScript中:

var div = document.createElement("div");
div.innerHTML = "<!--[if lte IE 9]><i></i><![endif]-->"; 

If the variable "div" is set with the <i></i> value then you're dealing with an old version of IE 如果将变量“ div”设置为<i></i>值,则说明您正在处理的是旧版IE

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM