Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Make two changes</p> <ol> <li>remove action attribute value, i.e. change <code>action="test.php"</code> to <code>action=""</code> or you can remove it, its not needed.</li> <li>change <code>return false;</code> to <code>return true;</code> in js, <code>$('#f1').submit(function()</code></li> </ol> <p>(explanation of when to use return true/false, currently you requested an submit action, which was called from a jquery function, if from a javascript/jquery you are returning false it means that the current request i.e. submit will not occur. in case of true, the submit will occur. we use false if cases when we are validating something and the user has not added correct output so we don't want to submit the page until he corrects the data. also action is not required in this case as you are submitting via jquery so you can remove the action="" attribute from the form)</p> <p>also you already have <code>html</code> tags in test.php, including it inside test2.php will create issues.</p> <p><strong>suggestion call test.php directly, you don't need test2.php.</strong> </p> <p>Here's the full code for test.php,</p> <pre><code>&lt;?php if (isset($_POST['submit'])) { $arr=array(); foreach ($_POST as $key =&gt; $value) { $arr[$key]=$value; } print_r($arr); } ?&gt; &lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;title&gt; Form &lt;/title&gt; &lt;script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"&gt; &lt;/script&gt; &lt;link rel="stylesheet" href="css/main.css" /&gt; &lt;/head&gt; &lt;body&gt; &lt;div id="content" id="login_form"&gt; &lt;form method="post" id="f1" name="f1" action=""&gt; &lt;table&gt; &lt;tr&gt; &lt;td&gt;Name :&lt;/td&gt;&lt;td&gt;&lt;input type="text" name="name"/&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;Register Number :&lt;/td&gt;&lt;td&gt;&lt;input type="text" name="regno"/&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;Date of Birth :&lt;/td&gt;&lt;td&gt;&lt;input type="text" name="dob"/&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;input type="submit" id="b1" name="submit" value="Submit" style="font-size:16px;"/&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/form&gt; &lt;/div&gt; &lt;script&gt; $('#f1').submit(function() { $.ajax({ data: $(this).serialize(), type: $(this).attr('post'), url: $(this).attr('test.php'), success: function(response) { $('#content').html(response); } }); return true; }); &lt;/script&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
    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.
    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