2012-12-01 113 views
3

以下是脚本。它在所有其他浏览器中工作正常,所以我认为这是一个缓存问题,但不是真的。我几个小时一直在敲我的头,没有任何工作。Ajax无法在IE中加载

$.ajaxSetup({ 
    cache: false 
}); 

$("#send").live('click', function() { 
    console.log("AAAAA"); 
    $("#loader").show(); 
    $form = $('#reservationForm'); 

    $inputs = $form.find('input[name^="entry"]'), 
    serializedData = $('#reservationForm :input[name^="entry"]').serialize(); 

    console.log(serializedData); 
    serializedData += "&pageNumber=0&backupCache=1&submit=Submit"; 

    // fire off the request to /form.php 
    $.ajax({ 
     url: "https://docs.google.com/spreadsheet/formResponse?formkey=d", 
     // url: "https://docs.google.com/spreadsheet/formResponse?formkey=d;ifq", 
     type: "post", 
     data: serializedData, 
     // callback handler that will be called on success 
     success: function (response, textStatus, jqXHR) { 
      // log a message to the console 
      console.log("Hooray, it worked!"); 
      $("#loader").hide(); 
      document.getElementById('error<?php echo"$uname";?>').innerHTML = error; 
      $("#success").fadeIn(); 
      setTimeout(function() { 
       $("#success").fadeOut(); 
      }, 5000); 
     }, 
     // callback handler that will be called on error 
     error: function (jqXHR, textStatus, errorThrown) { 
      // log the error to the console 
      console.log("The following error occured: " + textStatus, errorThrown); 
      alert('Due to an unknown error, your form was not submitted, please resubmit it or try later.'); 
     }, 
     // callback handler that will be called on completion 
     // which means, either on success or error 
     complete: function() { 
      // enable the inputs 
      $inputs.removeAttr("disabled"); 
     } 
    }); 

    // prevent default posting of form 
    event.preventDefault(); 

}); 
+0

我已经为您的javascript读取和删除missplaced“ – GottZ

+0

可以考虑尝试代码我编辑的方式 – GottZ

+0

,你可以发布你的HTML代码 – mikipero

回答

2

console.log在IE中打开Developer Tools(F12打开)后可用。尝试将其打开或在代码中使用警报。 或使用try catch;

try{ 
    console.log('worked') 
} 
catch(err){ 
} 

,你可能要检查,如果你的事件变量是不确定的:

event= event || window.event; 
event.preventDefault(); 
+1

是的,'console.log'在IE中打破了你的javascript。另一种选择是使用类似H5BP中的脚本(https://github.com/h5bp/html5-boilerplate/blob/master/js/plugins.js ),它定义了浏览器中没有作为noop的方法,因此不会导致错误。 – ultranaut

+0

有关如何使用插件js的一个小例子将非常有用。 – emuigai

0

在你是不是在处理程序中添加“事件”的声明剧本的开头:

$("#send").live('click', function() { 

应该是:

$("#send").live('click', function (e) { 

,并在脚本的末尾没有为变量事件的引用:

// prevent default posting of form 
event.preventDefault(); 

我认为,IE浏览器不具有全局事件对象“preventDefualt”功能(你所引用):这函数被添加到由jQuery传递的“e”事件对象。无论如何,在所有其他浏览器中,“事件未定义”都会失败。试试这个太:

// prevent default posting of form 
e.preventDefault(); 

附加的注释:jQuery开发团队目前不鼓励使用“实时”事件绑定功能,而是使用了“上”功能的等价形式。

0

IE不理解ajax中响应的内容类型。所以把你的dataType值放在请求中,它应该工作。例如对于例如 -

dataType: ($.browser.msie) ? "text" : "xml"