Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Either change your PHP to</p> <pre><code>if(isset($_POST['fname']) &amp;&amp; isset($_POST['lname'])){ $fname = $_POST['fname']; $lname = $_POST['lname']; $string = $fname."&lt;br /&gt;".$lname; echo $string; } </code></pre> <p>And your jQuery to</p> <pre><code>$(document).ready(function(){ $('input[name="submit"]').click(function(){ var fname = $('input[name="fname"]').val(); var lname = $('input[name="lname"]').val(); $.ajax({ type: 'POST', url: 'index.php', data: {fname:fname, lname:lname}, success: function(response){ console.log(response); // YOUR OWN LOGIC // IE: $('#my_div').append(response); } }); }); }); </code></pre> <p>Or change your PHP to</p> <pre><code>if(isset($_POST['fname']) &amp;&amp; isset($_POST['lname'])){ $response = array(); $response['fname'] = $_POST['fname']; $response['lname'] = $_POST['lname']; echo json_encode($response); } </code></pre> <p>And your jQuery to</p> <pre><code>$(document).ready(function(){ $('input[name="submit"]').click(function(){ var fname = $('input[name="fname"]').val(); var lname = $('input[name="lname"]').val(); $.ajax({ type: 'POST', url: 'index.php', data: {fname:fname, lname:lname}, dataType:"json" success: function(response){ response = eval(response); console.log('First name:' + response.fname); console.log('Last name:' + response.lname); // YOUR OWN LOGIC // IE: $('#my_div').append('Last name: ' + response.lname); } }); }); }); </code></pre> <p>I haven't tested any of it but it should put you on the right path. You can also use <code>beforeSend</code> and <code>error</code> / <code>fail</code> callbacks to debug and don't forget to check for a response (Firebug is great for this) it helps a lot.</p>
    singulars
    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.
 

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