jQuery / AJAX:代码适用于Chrome但不适用于IE

时间:2013-05-12 01:49:43

标签: javascript jquery ajax internet-explorer-9

我正在处理一个验证表单,我正在从html字段发送数据,JS用PHP文档拉取验证并通过AJAX发送回来,它在Chrome中工作得很好但不是Internet Explorer(我在IE9中测试它:

function Checkfiles() {
  var fup = document.getElementById('flUpload');
  var fileName = fup.value;
  var ext = fileName.substring(fileName.lastIndexOf('.') + 1);
  var chkext = ext.toLowerCase();
  if(chkext=="gif" || chkext=="jpg" || chkext=="jpeg" || chkext=="png") { return true; } else { return false; }
} // Checkfiles

function Checksize() { 
var iSize;
if ($("#flUpload")[0].files[0]){ iSize = ($("#flUpload")[0].files[0].size / 1024);}
if(Checkfiles()==true && iSize <= 51.200) { return true; } else { return false; }
} //Checksize

$(document).ready(function() {

   $("#ff1").submit(function(e){
   // prevent submit
   e.preventDefault();

   var email = document.getElementById("email").value;
   var title = document.getElementById("title").value;
   var url = document.getElementById("url").value;

   var parametros = {"emaail":email, "tiitle":title, "uurl":url};
   $.ajax({
    data: parametros,
    url: 'validate.php',
    type: 'post',
    context: this,
    error: function (response) {
        alert("An error has occurred! Try Again!");
    },
    success: function (response) {
        if($.trim(response)=='b' && Checksize()==true) { 
            this.submit(); // submit, bypassing jquery bound event
        } 
        else {
            if (Checksize()==true) {
                $("#ajax_call_val").html('<div id="validation"><ul>'+response+'</ul></div>');
            } else {
                if(response!='b') {
                $("#ajax_call_val").html('<div id="validation"><ul>'+response+'<li>Only GIF, PNG, JPG images, smaller than 50 KB</li></ul></div>');
                } else { $("#ajax_call_val").html('<div id="validation"><ul><li>Only GIF, PNG, JPG images, smaller than 50 KB</li></ul></div>'); }
            }
        }
    }
});

   });

});

难怪为什么不在IE中工作?提前谢谢。

0 个答案:

没有答案