Note that there are some explanatory texts on larger screens.

plurals
  1. POStrange behavior after ajax call
    primarykey
    data
    text
    <p>I'm working on a "subscription module" for a website, everything works fine except<br> the Ajax part. </p> <p>When I click the <strong>first</strong> time on "subscribe" the button changes to "unsubscribe", but if i click on "unsubscribe" button again without refreshing the page, the button changes to "subscribe" and than to "unsubscribe" again. </p> <p>Like if I clicked it twice.</p> <p>This is what I can see from "chrome -> network tab"</p> <pre><code>engine/ajax/mywatch.php?subscribe_id=3385&amp;action=plus&amp;skin=Default engine/ajax/mywatch.php?subscribe_id=3385&amp;action=minus&amp;skin=Default </code></pre> <p>html</p> <pre><code>&lt;a id="subscript-id-3385" onclick="doMywatch('3385', 'plus'); return false;" &gt;subscribe&lt;/a&gt; </code></pre> <p>javascript</p> <pre><code>&lt;script&gt; function doMywatch(a,b){ShowLoading("");$.get(root+"engine/ajax/mywatch.php",{subscribe_id:a,action:b,skin:skin},function(b){HideLoading("");$("#subscript-id-"+a).html(b)});return!1} &lt;/script&gt; </code></pre> <p>php</p> <pre><code> if( $_GET['action'] == "plus" ) { echo &lt;&lt;&lt;HTML &lt;script&gt; alert('plus '); &lt;/script&gt; HTML; $row = $db-&gt;super_query("SELECT subscriptions FROM " . PREFIX . "_mywatch WHERE user_id={$member_id['user_id']}" ); $list = explode(",", $row['subscriptions']); foreach ( $list as $daten ) { if( $daten == $id ) $achecker = "stop"; } $error = ""; if( $achecker != "stop" ){ $list[] = $id; $subsc = $db-&gt;safesql(implode( ",", $list )); //$subsc = implode( ",", $list ); if( $row['subscriptions'] == "" ) $subsc = $id; $db-&gt;query( "UPDATE " . PREFIX . "_mywatch set subscriptions='$subsc' where user_id = '{$member_id['user_id']}'" ); } $buffer = "&lt;a onclick=\"doMywatch('" . $id . "', 'minus'); \" title=\"" . $lang['news_minfav'] . "\"&gt;unsubscribe&lt;/a&gt;"; } elseif( $_GET['action'] == "minus" ) { echo &lt;&lt;&lt;HTML &lt;script&gt; alert('minus '); &lt;/script&gt; HTML; $error = ""; $row = $db-&gt;super_query("SELECT subscriptions FROM " . PREFIX . "_mywatch WHERE user_id={$member_id['user_id']}" ); $list = explode(",", $row['subscriptions']); foreach ( $list as $daten ) { if( $daten == $id ) $achecker = "stop"; } if( $achecker == "stop" ){ $list = array_merge(array_diff($list, array($id))); $subsc = $db-&gt;safesql(implode( ",", $list )); //$subsc = implode( ",", $list ); $db-&gt;query( "UPDATE " . PREFIX . "_mywatch set subscriptions='$subsc' where user_id = '{$member_id['user_id']}'" ); } $buffer = "&lt;a onclick=\"doMywatch('" . $id . "', 'plus'); \" title=\"" . $lang['news_minfav'] . "\"&gt;Подписатся&lt;/a&gt;"; } else die( "error" ); $db-&gt;close(); @header( "Content-type: text/html; charset=" . $config['charset'] ); echo $buffer; </code></pre>
    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.
    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