Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You have several error is your code:</p> <ol> <li><p>Change date to data</p> <pre><code>data : {username : 'subin', password : 'passwordx'}, </code></pre></li> <li><p>Remove this line, it will prevent Phonegap from successful posting:</p> <pre><code>xhrFields : {withCredentials: true}, </code></pre></li> <li><p>In your beforeSend and complete use this function to show loader:</p> <pre><code>$.mobile.loading('show'); </code></pre> <p>and </p> <pre><code>$.mobile.loading('hide'); </code></pre> <p>your current ones are deprecated in jQuery 1.2+.</p></li> </ol> <p>Your final code should look like this:</p> <pre><code>$.ajax({ type : "POST", url : "http://domain/public/login", 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('Works!'); }, error : function() { //console.error("error"); alert('Now working!'); } }); </code></pre> <p>Proof that it is working, just run it from the disk and not from a server because you will get a CROSS domain error:</p> <pre><code>&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;title&gt;jQM Complex Demo&lt;/title&gt; &lt;meta http-equiv='Content-Type' content='text/html; charset=utf-8'/&gt; &lt;meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; minimum-scale=1.0; user-scalable=no; target-densityDpi=device-dpi"/&gt; &lt;link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.1/jquery.mobile-1.3.1.min.css" /&gt; &lt;script src="http://code.jquery.com/jquery-1.9.1.min.js"&gt;&lt;/script&gt; &lt;script src="http://code.jquery.com/mobile/1.3.1/jquery.mobile-1.3.1.min.js"&gt;&lt;/script&gt; &lt;script&gt; $.ajax({ type : "POST", url : "http://domain/public/login", 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('Works!'); }, error : function() { //console.error("error"); alert('Not working!'); } }); &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;div data-role="page" id="index"&gt; &lt;div data-theme="b" data-role="header"&gt; &lt;h1&gt;Index page&lt;/h1&gt; &lt;/div&gt; &lt;div data-role="content"&gt; &lt;/div&gt; &lt;/div&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload