Note that there are some explanatory texts on larger screens.

plurals
  1. POPost form data to another PHP page, Get the JSON and direct based on parsing the JSON
    text
    copied!<p>Ok So I have a basic login page with a form:</p> <pre><code>&lt;form name="register" class="form-horizontal" id="signup" onsubmit="return validateForm(this);" action="check.php"&gt; &lt;div class="control-group input-append"&gt; &lt;label for="text" class="control-label"&gt;Name&lt;/label&gt; &lt;div class="controls"&gt; &lt;input id="name" name="name" type="name" placeholder="Enter your name"/&gt; &lt;/div&gt; &lt;/div&gt; &lt;br&gt; &lt;div class="control-group input-append"&gt; &lt;label for="passwd" class="control-label"&gt;Password&lt;/label&gt; &lt;div class="controls"&gt; &lt;input id="pass" name="pass" type="pass" placeholder="Enter your password"/&gt; &lt;/div&gt; &lt;/div&gt; &lt;br&gt; &lt;div class="control-group"&gt; &lt;div class="controls"&gt; &lt;div class="left1"&gt; &lt;input type="submit" name="submit" class="btn btn-success"/&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;br&gt; &lt;/form&gt; </code></pre> <p>On clicking submit I need to post the name and password to <code>check.php</code>. I do not want the browser to refresh the page to <code>check.php</code>.</p> <p>It should get the resulting JSON array, parse it and based on that redirect if the login is successful. </p> <p>Right now i can either post or get but not both. And I don't want the browser to refresh the page to <code>check.php</code>. </p> <p><strong>UPDATE:</strong></p> <p>I'm still not getting this to work. Have a look please.</p> <pre><code> &lt;form class="form-horizontal" id="login-form"&gt; &lt;div class="control-group input-append"&gt; &lt;label for="text" class="control-label"&gt;Email&lt;/label&gt; &lt;div class="controls"&gt; &lt;input name="email" id="email" type="email" value="" placeholder="Enter your email"/&gt; &lt;/div&gt; &lt;/div&gt; &lt;br&gt; &lt;div class="control-group input-append"&gt; &lt;label for="passwd" class="control-label"&gt;Password&lt;/label&gt; &lt;div class="controls"&gt; &lt;input name="passwd" id="passwd" type="password" value="" placeholder="Enter your password"/&gt; &lt;/div&gt; &lt;/div&gt; &lt;br&gt; &lt;div class="control-group"&gt; &lt;div class="controls"&gt; &lt;div class="left1"&gt; &lt;input type="button" id="login" value="Login" class="btn btn-success"/&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;br&gt; &lt;/form&gt; &lt;/div&gt; &lt;/div&gt; &lt;/body&gt; &lt;script&gt; $('#login').click(function(){ $.ajax({ url:"login.php", type:'POST', data: $("#login-form").serialize() }).done(function(data){ alert(JSON.stringify(data)); }); } }); &lt;/script&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