使用$ .ajax jquery mobile发送和接收

时间:2013-10-10 00:40:13

标签: php ajax jquery jquery-mobile

我收到此代码的错误但它应该有效。我想将数据发送到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!');                  
                 }
            });     
        });
    });

1 个答案:

答案 0 :(得分:0)

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

标题(&#39; Access-Control-Allow-Origin:*&#39;); 标题(&#39; Access-Control-Allow-Methods:GET,POST,PUT&#39;);