0

I am getting error for this code but it should work. I want to send data to loginck.php and get the server response. Any error?

<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!');                  
                 }
            });     
        });
    });
R. David
  • 80
  • 1
  • 8
  • what is your error? and what is in the console log? – KeepCalmAndCarryOn Oct 10 '13 at 00:55
  • im getting alert "not working!" – R. David Oct 10 '13 at 01:03
  • can you call `loginck.php?username=subin&password=passwordx` directly from the browser? are you sure there is nothing in the log http://stackoverflow.com/questions/4743730/what-is-console-log-and-how-do-i-use-it – KeepCalmAndCarryOn Oct 10 '13 at 01:14
  • yes i can call 'loginck.php?username=subin&password=passwordx'. thr is no log. – R. David Oct 10 '13 at 01:21
  • it may be a long shot but if the beforeSend callback returns false then the request is cancelled, also why do you have crossDomain set? you can pass parameters into the error event to see whats happening `error: function( jqXHR jqXHR, String textStatus, String errorThrown ){...}` – KeepCalmAndCarryOn Oct 10 '13 at 02:07
  • 1
    try using jqm 1.3.2 and jq 1.9.1 Also, replace `window.load` with `$(document).on('pageinit', function { ... });` – Omar Oct 10 '13 at 14:29
  • @Omar thnx for your reply bt it fixed already. – R. David Oct 13 '13 at 22:27

1 Answers1

0

I had the same problem but found a way out. you can add the following header specifiers at the top of your php file>>

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

James Shisiah
  • 353
  • 4
  • 14