Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><code>$.post()</code> is an abbreviated form of the $.ajax() structure. I usually prefer to use the <code>$.ajax()</code> structure because:</p> <ul> <li>It's easier to see if I've missed anything</li> <li>I can more easily add additional params, such as <code>asynch: false,</code></li> <li>When new to ajax I found it considerably easier to troubleshoot this structure</li> </ul> <p>In your case, you might find your problem easier to solve in a <code>$.ajax()</code> structure, since it would be easier to see that <em>a second ajax call (that depends on the outcome of a first ajax call) must happen in the success function of the first ajax call</em>.</p> <p>Here is a standalone example (too bad jsFiddle cannot handle ajax...):</p> <p>TESTER.PHP</p> <pre><code>&lt;html&gt; &lt;head&gt; &lt;script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"&gt;&lt;/script&gt; &lt;script type="text/javascript"&gt; $(document).ready(function() { $('#eml').focus(); $('#mybutt').click(function() { var $a = $('#eml').val(); var $b = $('#pw').val(); //alert('Email: ' +$a+ ' Pass: ' +$b); $.ajax({ type:"POST", url: "yourphpfile.php", data: 'email=' +$a+ '&amp;pass=' +$b, success: function(data) { alert(data); var aData = data.split('|'); var name = aData[0]; var code = aData[1]; alert('Name: ' +name+ ' Code: ' +code); $.ajax({ type:"POST", url: "yourphpfile.php", data: 'name=' +name+ '&amp;code=' +code, success: function(newdata) { alert(newdata); } //END success_ajax2 }); //END ajax() #2 } //END success_ajax1 }); //END ajax() #1 }); //END mybutt.click() }); //END $(document).ready() &lt;/script&gt; &lt;/head&gt; &lt;body&gt; Email: &lt;br /&gt; &lt;input type="text" id="eml" /&gt;&lt;br /&gt; Password: &lt;br /&gt; &lt;input type="password" id="pw" /&gt;&lt;br /&gt; &lt;input type="button" id="mybutt" value="Submit"&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <hr> <p><strong>yourphpfile.php</strong></p> <pre><code>&lt;?php if (isset($_POST['email'])) { $e = $_POST['email']; $p = $_POST['pass']; $name = 'Bob'; $code = '1234'; $resp = $name .'|'. $code; echo $resp; }else if (isset($_POST['name'])) { $n = '&lt;h1&gt;Here is something new&lt;/h1&gt;'; echo $n; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

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