Note that there are some explanatory texts on larger screens.

plurals
  1. POjQuery Ajax Call inside of PHP
    text
    copied!<p>I'm clearly doing something wrong here, but I can't figure out why the Ajax isn't firing and instead insists upon a page load. The newBatable() fires fine, I just can't seem to get the vote to respect the ajax call.</p> <p>HTML - not sure how to put html in here as code :/ - I feel dumb. </p> <pre><code>&lt;form class="form-horizontal" id="batable1" action="vote.php" method="GET"&gt; &lt;div id="success-vote-1"&gt;&lt;/div&gt; &lt;input type="radio" name="batableResult" value=" include ()" /&gt; include ()&lt;br/&gt; &lt;input type="radio" name="batableResult" value="require ()" /&gt;require ()&lt;br/&gt; &lt;input type="radio" name="batableResult" value="both of above" /&gt;both of above&lt;br/&gt; &lt;input type="radio" name="batableResult" value="None of above" /&gt;None of above&lt;br/&gt; &lt;button class="btn btn-primary" onClick="vote(1)"&gt;Vote&lt;/button&gt; &lt;input type="hidden" name="batableId" id="batable-id" value="1"/&gt; &lt;/form&gt; </code></pre> <p>JS - the console display everything I want, the php script processes everything nicely and functions perfectly, it is just it has to load the php in the browser so it's not using AJAX</p> <pre><code>/***************************************/ function newBatable() { var batableData = $('#new-batable').serialize(); //console.log(batableData); $.ajax({ url: "process.php", data: batableData, success: function(data){ $('#success-new-batable').html(data); } }); } /***************************************/ function vote(poll_id) { //console.log(poll_id) var batableId = "#batable" + poll_id; //console.log(batableId) var pollData = $(batableId).serialize(); //console.log(pollData); $.ajax({ url: "vote.php", data: pollData, success: function(data){ var batable_success_id = "#success-vote" + poll_id; $(batable_success_id).html(data); } }); } </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