Note that there are some explanatory texts on larger screens.

plurals
  1. POAjax doesn't work on multiple divs
    primarykey
    data
    text
    <p>Probably this question is very dumb, but i've tried solving for days and still couldn't get it done. <strong>Whoever can solve this please name a price and give me you paypal, money goes to you</strong> :).Basically, i want to put a add to wish list button to a series of div, id = "imgforplaces_thumbnail" (see my php function), the while loop in php function will then generate a number of div "imgforplaces_thumbnail", i.e. 12. I have tried to var_dump($row['id']); for each different item in the while loop, they have shown i.e. 1,2,3,4,5,6 etc.Basically the add to wish list button, class ="addbutton","deletebutton", when i click on it, will do an ajax call, either Addtobucketlist() or Deletefrombucketlist() (see header). depending on the status of checkifadded(), it will show or hide class "addbutton" or "deletebutton". Now my problem is that when i execute the codes, when i click on the first check button, it simply runs the last check button function!i.e. $row['id']=6. </p> <p>One thing worth to note is that if i am not using multiple divs, it works like magic! but not when there are more than one div "imgforplaces_thumbnail"</p> <p>You can see demo here: <a href="http://utourpia.me/php/dreamtrip.php" rel="nofollow">http://utourpia.me/php/dreamtrip.php</a></p> <p>This is my header:</p> <pre><code> $(document).ready(function(){ $('.addBucket').submit(function(e) { Addtobucketlist(); e.preventDefault(); }); }); $(document).ready(function(){ $('.deleteBucket').submit(function(e) { Deletefrombucketlist(); e.preventDefault(); }); }); </code></pre> <p>i will do an ajax call:</p> <pre><code>function Addtobucketlist() { hideshow('loading',1); error(0); $.ajax({ type: "POST", url: "http://utourpia.me/php/addtobucketlist.php", data: $('.addBucket').serialize(), dataType: "json", success: function(msg){ if(parseInt(msg.status)==1) { if ($('.addbutton').is(":visible")){ //hide the form $('.addbutton').fadeOut(1); //show the success message $('.deletebutton').fadeIn(1); } else { //hide the form $('.addbutton').fadeIn(1); //show the success message $('.deletebutton').fadeOut(1); } } else if(parseInt(msg.status)==0) { error(1,msg.txt); } hideshow('loading',0); } }); } function Deletefrombucketlist() { hideshow('loading',1); error(0); $.ajax({ type: "POST", url: "http://utourpia.me/php/deletefrombucketlist.php", data: $('.deleteBucket').serialize(), dataType: "json", success: function(msg){ if(parseInt(msg.status)==1) { if ($('.addbutton').is(":visible")){ //hide the form $('.addbutton').fadeOut(1); //show the success message $('.deletebutton').fadeIn(1); } else { //hide the form $('.addbutton').fadeIn(1); //show the success message $('.deletebutton').fadeOut(1); } } else if(parseInt(msg.status)==0) { error(1,msg.txt); } hideshow('loading',0); } }); } </code></pre> <p>this is my php function:</p> <pre><code>$result = mysql_query("select SQL_CALC_FOUND_ROWS * from places order by id asc limit 12"); while ($row = mysql_fetch_array($result)) { echo '&lt;div id=imgforplaces_thumbnail&gt;'; $location_id = $row['id']; if (check_if_added($users_id, $location_id) == "yes") { echo '&lt;div class=addbutton&gt;'; echo '&lt;form class=deleteBucket action="http://utourpia.me/php/deletefrombucketlist.php" method=post&gt;'; echo '&lt;input type="hidden" name="Delete1" value='.$location_id.' /&gt;'; echo '&lt;input type="image" src="../images/checked.png" name="Delete" value="delete"&gt;&lt;img id=loading src="http://utourpia.me/images/loading.gif" alt="working.." /&gt;'; echo '&lt;/form&gt;'; echo '&lt;/div&gt;'; echo '&lt;div class="deletebutton"&gt;'; echo '&lt;form class=addBucket action="http://utourpia.me/php/addtobucketlist.php" method=post&gt;'; echo '&lt;input type="hidden" name="Add1" value='.$location_id.' /&gt;'; echo '&lt;input type="image" src="../images/haventchecked.png" name="Add" value="add"&gt;&lt;img id=loading src="http://utourpia.me/images/loading.gif" alt="working.." /&gt;'; echo '&lt;/form&gt;'; echo '&lt;/div&gt;'; } else if (check_if_added($users_id, $location_id) == "no") { echo '&lt;div class=addbutton&gt;'; echo '&lt;form class=addBucket action="http://utourpia.me/php/addtobucketlist.php" method=post&gt;'; echo '&lt;input type="hidden" name="Add1" value='.$location_id.' /&gt;'; echo '&lt;input type="image" src="../images/haventchecked.png" name="Add" value="add"&gt;&lt;img id=loading src="http://utourpia.me/images/loading.gif" alt="working.." /&gt;'; echo '&lt;/form&gt;'; echo '&lt;/div&gt;'; echo '&lt;div class="deletebutton"&gt;'; echo '&lt;form class=deleteBucket action="http://utourpia.me/php/deletefrombucketlist.php" method=post&gt;'; echo '&lt;input type="hidden" name="Delete1" value='.$location_id.' /&gt;'; echo '&lt;input type="image" src="../images/checked.png" name="Delete" value="delete"&gt;&lt;img id=loading src="http://utourpia.me/images/loading.gif" alt="working.." /&gt;'; echo '&lt;/form&gt;'; echo '&lt;/div&gt;'; } echo '&lt;/div&gt;'; //end div imgforplaces_thumbnail echo '&lt;br /&gt;'; } </code></pre>
    singulars
    1. This table or related slice is empty.
    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.
 

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