Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Add jQuery lib in your head and your jQuery perso (myjQuery.js) that you will use after for ajax</p> <p><strong>index.php</strong></p> <pre><code>&lt;script src="http://code.jquery.com/jquery-1.10.1.min.js"&gt;&lt;/script&gt; &lt;script src="/js/myjQuery.js"&gt;&lt;/script&gt; </code></pre> <p>Create your form without action on your form.</p> <pre><code>&lt;html&gt; &lt;form name="g-form" class="goat-vote"&gt; &lt;input type="text" name="g-product" placeholder="Brand / Product Name" style="-moz-border-radius: 5px; border-radius: 5px; padding-left:20px; opacity:.5; border:none; margin-left:110px; width:440px; height:38px; font-family:'Proxima Nova Rg';color:#000; font:1.6em;" /&gt; &lt;p class="g-question"&gt;Why you love it?&lt;/p&gt; &lt;textarea name="g-reason" style="-moz-border-radius: 5px; border-radius: 5px; padding:5px; opacity:.5; border:none; margin-left:110px; width:450px; height:150px; font-family:'Proxima Nova Rg';color:#333; font-size:1em;"&gt;&lt;/textarea&gt; &lt;input name="g-btn" class="vote-btn" value="vote" style="margin-left:470px; cursor:pointer;"&gt; &lt;/form&gt; &lt;/html&gt; </code></pre> <p>Keep your exec.php like this </p> <p><strong>exec.php</strong></p> <pre><code>if ($_POST["g-product"] &amp;&amp; $_POST["g-reason"] != "" ) { $gproduct = $_POST["g-product"]; $greason = $_POST["g-reason"]; $insert ="INSERT INTO jovine.vote (vote_id ,product_name ,reason ,type) VALUES (NULL, '$gproduct', '$greason', 'goat')"; $result = mysql_query($insert,$con); echo "&lt;script&gt;"; echo "alert('Thank you. Your vote has been recorded.');"; echo "window.location.href='index.php?hidesubmit=1';"; echo "&lt;/script&gt;"; } </code></pre> <p>and create myjQuery.js</p> <p><strong>myjQuery.js</strong></p> <pre><code>$(document).ready(function(){ $(".vote-btn").on("click", function(){ g-product = $("input[name='g-product']").val(); g-reason = $("input[name='g-reason']").val(); $.ajax({cache:false,dataType:'html',crossDomain:true,type:'POST', url:'/php/exec.php',data : {g-product:g-product, g-reason:g-reason}, success:function(html){ console.log(html); }, error:function(j,t,e){ console.log('problem'); } }); }); }); </code></pre> <p>You can try this code, maybe there are problems with js path or php path of your files. And maybe some mistakes that you can correct.</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.
    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