Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy does text of previous links clicked on the page show up in an AJAX request?
    primarykey
    data
    text
    <p>Here's a bootstrap modal that I'm putting the result of AJAX request in </p> <pre><code>&lt;div class="modal hide" id="myModal"&gt; &lt;div class="modal-header"&gt; &lt;button type="button" class="close" data-dismiss="modal"&gt;×&lt;/button&gt; &lt;h3&gt;Modal header&lt;/h3&gt; &lt;/div&gt; &lt;div id="modal-body"&gt;&lt;/div&gt; &lt;div class="modal-footer"&gt; &lt;a href="#" class="btn" data-dismiss="modal"&gt;Close&lt;/a&gt; &lt;/div&gt; &lt;/div&gt; </code></pre> <p>The javascript code looks like this </p> <pre><code>&lt;script type="text/javascript"&gt; $('#myModal').modal('hide'); $('div.divBox a').click(function(){ var vendor = $(this).text(); console.log(vendor); $('#myModal').on('show', function(){ $.ajax({ type: "GET", url: "ip.php", data: "id=" + vendor, success: function(html){ $("#modal-body").html(html); } }); }); }); $('#myModal').on('hide', function () { $("#modal-body").empty(); &lt;?php unset($_GET); ?&gt;; }) &lt;/script&gt; </code></pre> <p>the <strong>ip.php</strong> file is </p> <p>The anchor links code looks like this </p> <pre><code> &lt;tbody&gt; &lt;?php foreach ($rowarr as $k =&gt; $v) { ?&gt; &lt;tr&gt; &lt;td&gt;&lt;?php echo $k ?&gt;&lt;/td&gt; &lt;td&gt; &lt;div class="divBox"&gt; &lt;a data-toggle="modal" href="#myModal"&gt;&lt;?php echo $v; ?&gt;&lt;/a&gt; &lt;/div&gt; &lt;/td&gt; &lt;/tr&gt; &lt;?php } ?&gt; &lt;/tbody&gt; </code></pre> <p>$k is a number. $v is a name with spaces and special characters.</p> <p>console.log(vendor) shows me the text of the link I clicked in CDT. But the output of the modal changes. It goes through all the links text I clicked previously, and keeps replacing them and finally ends up at the most current link text.</p> <p>So if clicked the links in this order the console output looks like this</p> <pre><code>Microsoft Corporation IBM Corp Hewlett-Packard Apple </code></pre> <p>The text in the modal will start out as </p> <pre><code>Array ( [id] =&gt; Microsoft Corporation ) </code></pre> <p>then replace with </p> <pre><code>Array ( [id] =&gt; IBM Corp ) </code></pre> <p>then replace with </p> <pre><code>Array ( [id] =&gt; Hewlett-Packard) </code></pre> <p>then end up with </p> <pre><code>Array ( [id] =&gt; Apple ) </code></pre> <p>What is keeping track of the links clicked on the page ? Do I need to reset it every time a new link is clicked ?</p> <p>EDIT: In response to "What have you tried?"</p> <p>I added the <code>$("#modal-body").empty();</code> in there in hope that maybe it's the modal body that I need to cleared. That wasn't it. Then I thought maybe the GET variable need to be reset on closing of the modal, so I added the <code>&lt;?php unset($_GET); ?&gt;;</code>. But the print_r($_GET) shows that the array only contains one array element, not all the links clicked previously. So I can't figure where else the history of the links clicked be stored.</p>
    singulars
    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.
 

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