2013-04-26 17 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){