Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to handle POST requests using JQuery .load(this.href)?
    text
    copied!<p>This is building from my previous question located <a href="https://stackoverflow.com/questions/18896641/load-a-php-file-into-a-div-using-jquery">here</a></p> <p>I have a form (tsconfig.php) load into a div using .load(this.href) which posts the results to itself, however the form reloads the entire page and displays tsconfig.php rather than placing the output into the div. How can I resolve this so that the output is displayed in place of the form?</p> <p>P.S. Before you look ahead, I realize that some of the code is quite a mess and is probably not the best approach; it's code from an old script I'm trying to port across into a revamped script and I'm by no means experienced. I'm learning by doing.</p> <p>The link is:</p> <pre><code>&lt;li&gt;&lt;a class="ajax-link" href="/includes/scripts/tsconfig.php"&gt;TSConfig&lt;/a&gt;&lt;/li&gt; </code></pre> <p>The script is:</p> <pre><code>&lt;div class="grid_3" id="main_content"&gt; &lt;script&gt; $(function() { $("a.ajax-link").on("click", function(e) { e.preventDefault(); $("#main_content").load(this.href); }); }); &lt;/script&gt; &lt;/div&gt; </code></pre> <p>The form tsconfig.php is:</p> <pre><code>&lt;?php include("output_scripts.php"); ?&gt; &lt;h4&gt;TSConfig&lt;/h4&gt; &lt;form action="&lt;?php echo htmlentities($_SERVER['PHP_SELF']);?&gt;" method="post"&gt; &lt;table width="100%" cellpadding="10" cellspacing="0"&gt; &lt;tr&gt; &lt;td colspan="3" style="width:99%"&gt; &lt;label&gt;InstallShield Version&lt;/label&gt;&lt;br /&gt; &lt;select name="isVersion" onchange="javascript:setTimeout('__doPostBack(\'ddlVersion\',\'\')', 0)" id="isVersion" class="box"&gt; &lt;option selected="2012Spring" value="2012Spring"&gt;2012 Spring&lt;/option&gt; &lt;option value="2012"&gt;2012&lt;/option&gt; &lt;option value="2011"&gt;2011&lt;/option&gt; &lt;option value="2010"&gt;2010&lt;/option&gt; &lt;option value="2009"&gt;2009&lt;/option&gt; &lt;option value="2009 Express"&gt;2009 Express&lt;/option&gt; &lt;option value="IS2008"&gt;2008&lt;/option&gt; &lt;option value="IS 2008 Express"&gt;2008 Express&lt;/option&gt; &lt;/select&gt; &lt;tr&gt; &lt;td colspan="3" style="width:99%"&gt; &lt;input type="checkbox" name="no_internet" value="no_internet"&gt; no_internet &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td colspan="3" style="width:99%"&gt; &lt;input type="submit" name="submit" value="submit"&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/form&gt; &lt;?php if(isset($_POST['submit'])){ if ($isVersion == "IS2008" &amp;&amp; empty($_POST['no_internet']) || $isVersion == "IS 2008 Express" &amp;&amp; empty($_POST['no_internet'])) { echo $output_macrovision; } elseif ($isVersion == "IS2008" &amp;&amp; isset($_POST['no_internet']) || $isVersion == "IS 2008 Express" &amp;&amp; isset($_POST['no_internet'])) { echo $output_macrovision_no_internet; } elseif (isset($_POST['submit']) &amp;&amp; empty($_POST['no_internet'])) { echo $output_script; } elseif (isset($_POST['no_internet'])) { echo $output_script_no_internet; } } ?&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