2013-05-17 78 views
1

如果我在我的瀏覽器中嘗試下面的代碼,但是當我在我的設備(Samsung Galaxy S3)上嘗試它時,它不會完成AJAX請求。AJAX請求在移動設備上失敗

AJAX請求:

$.ajax({ 
    type: "POST", 
    url: "http://somelink.nl/mobileajax/ajax.php", 
    data: ({ 
     name: Username, 
     pass: Pass, 
     email: Email, 
     firstname: FirstName, 
     lastname: LastName 
    }), 
    cache: false, 
    dataType: "text", 
    success: alert('Succes') 
}); 

希望你們能幫幫我!

編輯:

感謝您的幫助,但它仍然是行不通的發現,它不是AJAX請求去錯了,但其他的東西在這裏是全碼:

的Javascript:

var app = { 
    // Application Constructor 
    initialize: function() { 
     this.bindEvents(); 
    }, 
    // Bind Event Listeners 
    // 
    // Bind any events that are required on startup. Common events are: 
    // 'load', 'deviceready', 'offline', and 'online'. 
    bindEvents: function() { 
     document.addEventListener('deviceready', this.onDeviceReady, false); 
    }, 
    // deviceready Event Handler 
    // 
    // The scope of 'this' is the event. In order to call the 'receivedEvent' 
    // function, we must explicity call 'app.receivedEvent(...);' 
    onDeviceReady: function() { 
     app.receivedEvent('deviceready'); 
    }, 
    // Update DOM on a Received Event 
    receivedEvent: function(id) { 
     var parentElement = document.getElementById(id); 
     var listeningElement = parentElement.querySelector('.listening'); 
     var receivedElement = parentElement.querySelector('.received'); 

     listeningElement.setAttribute('style', 'display:none;'); 
     receivedElement.setAttribute('style', 'display:block;'); 

     console.log('Received Event: ' + id); 
    } 
}; 

function register() 
    { 

     var Username = $.trim($("#Username").val()); 
     var Pass = $.trim($("#Password").val()); 
     var Email = $.trim($("#Email").val()); 
     var FirstName = $.trim($("#FirstName").val()); 
     var LastName = $.trim($("#LastName").val()); 

     if((Username.length > 0) && (Pass.length > 0) && (Email.length > 0) && (FirstName.length > 0) && (LastName.length > 0)) 
      { 
      $.ajax({ 
       type: "POST", 
       url: "http://quincycollijn.nl/mobileajax/ajax.php", 
       data: ({name: Username, pass: Pass, email: Email, firstname: FirstName, lastname: LastName}), 
       dataType: "text", 
       success: onSucces, 
       error: function(jq,status,message) { 
        alert('A jQuery error has occurred. Status: ' + status + ' - Message: ' + message); 
       } 
      }); 
     } else { 
      alert('Niks ingevult'); 
     } 


     function onSuccess() 
      { 
       alert('Result:'); 
      } 
} 

HTML:

<!DOCTYPE html> 
<html> 
    <head> 
    <title>My Page</title> 
    <meta name="viewport" content="width=device-width, initial-scale=1"> 
    <link rel="stylesheet" href="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.css" /> 
    <link rel="stylesheet" href="css/style.css" /> 
    <script src="phonegap.js"></script> 
    <script src="http://code.jquery.com/jquery-1.8.2.min.js"></script> 
    <script src="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.js"></script> 
    <script src="js/index.js"></script> 
    </head> 
    <body onLoad="onBodyLoad()"> 

    <div data-role="page" data-theme="a"> 

     <div data-role="header"> 
     <h1>Chatup!</h1> 
     </div><!-- /header --> 

     <div data-role="content"> 
     <div data-role="fieldcontain"> 
     <img src="img/img_placeholder.png" class="placeholder" align="center" rel="Placeholder" > 
      <input class="login-input" data-mini="true" type="text" id="FirstName" name="first_name" placeholder="First Name" data-theme="b" > 
     </br></br></br> 
      <input class="login-input" data-mini="true" type="text" id="LastName" name="last_name" placeholder="Last Name" data-theme="b" > 
     </br></br></br> 
      <input type="text" data-mini="true" name="username" id="Username" placeholder="Username" data-theme="b" > 
      </br> 
      <input type="text" data-mini="true" name="email" id="Email" placeholder="Email" data-theme="b" > 
      </br> 
      <input type="password" data-mini="true" id="Password" name="password" placeholder="Password" data-theme="b" > 
      </br> 

      <a href="#" class="register-button" data-role="button" data-theme="b">Register</a> 
     </div> 
     </div><!-- /content --> 
    </div><!-- /page --> 

    </body> 
</html> 
+0

你在s3上的其他瀏覽器上嘗試過嗎?像Opera Mini? –

回答

0

在第二行

我看到有一個不需要的單引號,可能會導致錯誤,這是一個錯字嗎?

+0

是的,這是一個錯字:) – user2118839

+0

你有沒有嘗試S3上的其他瀏覽器? –

+0

並嘗試 1.根據jQuery文檔 緩存添加錯誤處理 2.(默認值:true,false爲的dataType「腳本」和「JSONP」) 類型:Boolean 如果設置爲false,這將迫使請求的頁面不被瀏覽器緩存。注意:將緩存設置爲false只能在HEAD和GET請求中正常工作。它通過在GET參數中附加「_ = {timestamp}」來工作。其他類型的請求不需要該參數,除了在IE8中對POST已經請求的URL進行POST時以外。 –