0

我收到此代码的错误,但它应该可以工作。我想向loginck.php服务器发送数据并获得响应。有什么错误吗?

<link rel="stylesheet"  href="css/jquery.mobile-1.3.0-beta.1.css" />
<link rel="stylesheet" href="css/jqm-docs.css"/>

<script src="js/jquery-1.7.1.min.js"></script>
<script src="js/jqm-docs.js"></script>
<script src="js/jquery.mobile-1.3.0-beta.1.js"></script>

HTML:

    <div data-role="popup" id="popupLogin" data-theme="a" class="ui-corner-all">
        <form action="#" method="post" autocomplete="off">
            <div style="padding:10px 20px;">
              <h3>Please sign in</h3>
              <label for="un" class="ui-hidden-accessible">Username:</label>
              <input type="text" name="username" id="un" value="" placeholder="username" data-theme="a" />

              <label for="pw" class="ui-hidden-accessible">Password:</label>
              <input type="password" name="password" id="pw" value="" placeholder="password" data-theme="a" />

              <button type="submit" name="submit" id="submit" value="submit-value" data-theme="b">Sign in</button>
            </div>
        </form>
    </div>

$.ajax:

    $(window).load(function(e){
        $('#submit').bind('click', function(e)  {
            e.preventDefault();
            $.ajax({
                type       : "POST",
                url        : "loginck.php",
                crossDomain: true,
                beforeSend : function() {$.mobile.loading('show')},
                complete   : function() {$.mobile.loading('hide')},
                data       : {username : 'subin', password : 'passwordx'},
                dataType   : 'json',
                success    : function(response) {
                    //console.error(JSON.stringify(response));
                    alert(response);
                },
                error      : function() {
                    //console.error("error");
                    alert('Not working!');                  
                 }
            });     
        });
    });
4

1 回答 1

0

我有同样的问题,但找到了出路。您可以在 php 文件的顶部添加以下标头说明符>>

header('Access-Control-Allow-Origin: *'); header('Access-Control-Allow-Methods: GET, POST, PUT');

于 2015-08-01T06:04:42.443 回答