Note that there are some explanatory texts on larger screens.

plurals
  1. POload a php form in the same page using jquery and ajax
    primarykey
    data
    text
    <p>I want a function that loads the values from a PHP form and show the result in a div in the same file ;</p> <p>I have a form in PHP file with the code bellow :</p> <pre><code>&lt;?php echo "&lt;script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js'&gt;&lt;/script&gt;"; echo"&lt;script type='text/javascript' src='script.js'&gt;&lt;/script&gt;"; echo"&lt;form method='post' action='' &gt;"; echo " &lt;select name='mat'&gt;&lt;option value=''&gt;Choose: &lt;/option&gt;"; echo"&lt;option &gt;hello&lt;/option&gt;"; echo"&lt;/select&gt;"; echo"&lt;input type = 'submit' value='next' onclick='submit();' /&gt;"; echo"&lt;/form&gt;"; echo"&lt;div id ='result'&gt; &lt;/div&gt;"; ?&gt; </code></pre> <p>and the function in <code>script.js</code> is :</p> <pre><code>function submit() { $(function () { var mat = "mat"; var dataString = 'mat=' + mat; $.ajax({ type: "POST", url: "check.php", data: dataString, success: function (res) { goToByScroll("result"); $('#result').html("&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;").hide().fadeIn(2500, function () { $('#result').html(res + "&lt;br /&gt;&lt;br /&gt; Finished"); }); } }); return false; }); } </code></pre> <p>and the <code>check.php</code> that load the values is :</p> <pre><code>&lt;?php function safe($value) { htmlentities($value, ENT_QUOTES, 'utf-8'); return $value; } if (isset($_POST['mat'])) { $mat = safe($_POST['mat']); echo ($mat); } elseif (!isset($_POST['mat'])) { header('Location: error?mat=notfound'); } ?&gt; </code></pre> <p>But when I click next in the fist PHP file, it doesn't show anything, can you find the error?</p>
    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. 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