2012-03-12 21 views
1

jQuery代碼:的jQuery(。移動)不是在Android瀏覽器正確啓用

$.ajaxSetup({ cache: false }); 
$('#stid_status_msg').hide(); 
$('.SpeedTestId').blur(function(e) { 
    e.preventDefault(); 
    var stid = $('.SpeedTestId').val(); 
    var postString = 'stid=' + stid; 
/* $.ajax({ 
     cache: false, 
     url:"inc/check_stid.inc.php", 
     type:'POST', 
     data:postString, 
     success:function(msg) { 
      $('#stid_status_msg').html(msg); 
      $('#stid_status_msg').show(); 
     }, 
     error:function(error) { 
      $('#stid_status_msg').html('<font color="red">Error submitting results!' + error + '</font>'); 
      $('#stid_status_msg').show(); 
     } 
    });*/ 
    $.get("inc/check_stid.inc.php", { stid: stid }, function(msg) { 
      $('#stid_status_msg').html(msg); 
      $('#stid_status_msg').show(); 
    }); 
}); 

註釋掉$.ajax()方法我試圖最初,但很快發現$.get()是什麼,我試圖更好的方法做。但無論使用哪種方法,代碼在桌面瀏覽器(FF,IE,Chrome)中都能正常工作,但無法在Android瀏覽器中成功完成。

當我使用$.ajax(),我在Android瀏覽器首先掛起測試幾秒鐘,然後錯誤回調火災和我得到:

錯誤提交的結果! [object] [object]

我還應該注意到,當我在Android瀏覽器中啓用java控制檯時,它並不表示JS存在任何錯誤。

因此,我發現該腳本出於某種原因無法找到/加載inc/check_stid.inc.php。但爲什麼只在Android瀏覽器?

很顯然,我是一個jQuery新手,我很欣賞你們可以提供的任何見解。

編輯

我在我的Android安裝FF和代碼工作正常那裏。無論我遇到什麼特定於Android瀏覽器。很奇怪!

回答

0

一種error回調一個jQuery AJAX請求將被傳遞以下參數:

  1. jqXHR:一個串錯誤消息
  2. errorThrown:與AJAX請求
  3. textStatus相關XHR對象的包含錯誤特定信息的對象

您正在嘗試輸出jqXHR就好像它是一個字符串,而不是一個對象(就像它)。爲了得到一個有意義的錯誤消息,試試這個:

error:function(jqXHR, textStatus, errorThrown) { 

     //only log the objects if the current browser has a console.log function 
     if (typeof console == 'object' && typeof console.log == 'function') { console.log(jqXHR); console.log(errorThrown); } 

     $('#stid_status_msg').html('<font color="red">Error submitting results!' + textStatus + '</font>').show(); 
    } 

Google文檔$.ajax()http://api.jquery.com/jquery.ajax/

+0

感謝您的反饋。我試圖理解jqXHR對象以獲得有意義的錯誤輸出,但失敗了。這有助於爲我解決一些問題,謝謝。但是,現在它只輸出'錯誤提交結果!'在上面描述的相同的短暫掛起之後。任何其他的想法來得到這個底部?先謝謝你。 – 2012-03-12 19:40:07

相關問題