2015-05-22 47 views
2

我在我的網站(不是跨域)上發出AJAX請求時遇到問題。jQuery AJAX在FireFox中不起作用

這是我使用的代碼:

$("#submit").click(function(e){ 
     var nameW = $("#name").val(); 
     var teamValue = $("#team").val(); 
     $.ajax({ 
      type: "POST", 
      url: "/smoke/add.php", 
      data: { 
        name:nameW, 
        team:teamValue, 
        firstX:firstposition[2], 
        firstY:firstposition[3], 
        secondX:secondposition[2], 
        secondY:secondposition[3] 
       }, 
      success: function(response) { console.log("Response: " + response) }, 
      error: function(jqXHR, textStatus, errorThrown) { 
         console.log(JSON.stringify(jqXHR)); 
         console.log("AJAX error: " + textStatus + ' : ' + errorThrown); 
      } 
     }); 
    }); 

它在谷歌瀏覽器的工作,但不能在Firefox。所以我認爲我的ajax請求有問題。

+5

在日誌中是否有錯誤? – Mivaweb

+0

一點都不:{「readyState」:0,「responseText」:「」,「status」:0,「statusText」:「error」} javascript.js(regel 54) AJAX error:error: - Not an有用的錯誤 – top97

+1

另外我看不到你在add.php中訪問哪個函數?我現在沒有太多關於PHP的知識,但是你不必定義一個方法來調用你的ajaxcall? – Mivaweb

回答

2

您並未取消提交/點擊操作,因此該頁面將回發到服務器並取消請求。你需要防止默認。

$("#submit").click(function(e){ 
    e.preventDefault(); 
    ... 
+0

謝謝。就是這樣! – top97