2013-04-26 18 views
0

出于某种原因,我有一些奇怪的问题让AJAX在不同的Web浏览器上正常工作。有什么特别的东西是必要的,或者有什么窍门让事情在他们之间顺利进行?AJAX Broswer问题

我遇到的第一个问题是用下面的,它工作在Chrome完美,但什么事情都不在IE和Firefox:

function DeleteRideshare(pid){ 
    if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari 
     xmlhttp=new XMLHttpRequest(); 
    } 
    else{// code for IE6, IE5 
     xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); 
    }   
    // Verify 
    var conf = confirm("Are you sure you want to delete this rideshare?"); 
    if(conf == true){ 
     xmlhttp.open("POST","updaterideshare.php",true); 
     xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded"); 
     xmlhttp.send("delete=true&PostID="+pid);  
     location.reload();      
    }   
} 

我也有这个,这与铬一些元素的作品,并且根本不在ie和Firefox中:

$(document).ready(function(){ 
    $("#EditRideshareAjax").submit(function(){ 
     // Stop the from from submiting normally 
     event.preventDefault();   

     // get the values from the elements on the page 
     var values = $(this).serialize(); 

     $.ajax({ 
      type: "POST", 
      url: "updaterideshare.php", 
      data: values, 
      success:  function(msg){           
       location.reload(); 
      }, 
      error:function(){ 
       alert("An error has occured, please try again"); 
      } 
     }); 
    }); 
}); 

任何帮助或洞察力将不胜感激!谢谢!

+0

究竟是什么问题? – Joseph 2013-04-26 05:16:06

+0

当我在firefox中提交ajax请求并且没有任何事情发生时,但是当我使用chrome时工作完全正常,如果这很有意义 – user1875195 2013-04-26 05:17:48

+1

@ user1875195:您是否检查过控制台请求是否有效?也许在请求中没有包含的某些逻辑有问题。 – Zeta 2013-04-26 05:18:52

回答

1

你不必在函数中传递事件作为参数,然后使用它。

  $("#EditRideshareAjax").submit(function(event){