AJAX请求在移动设备上失败

时间:2013-05-17 13:36:56

标签: android ajax webrequest galaxy

如果我在浏览器中尝试以下代码,它可以正常工作,但是当我在我的设备(三星Galaxy S3)上试用它时,它无法完成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>

1 个答案:

答案 0 :(得分:0)

在第二行

我看到有一个不需要的单引号可能会导致错误,这是一个错字吗?