Note that there are some explanatory texts on larger screens.

plurals
  1. POSend extra data value with PHP/jQuery UI to ajax.php file
    primarykey
    data
    text
    <p>I am trying to send an extra <code>$php_var</code> with jQuery to an Ajax post function. In the 1st <code>$.ajax</code> I have:</p> <pre><code> $('.ui-icon-closethick').click(function(e) { e.preventDefault(); var parent = $(this).parent().parent(); $.ajax({ type: "POST", url: "server_items_reorder.php", data: 'id=' + parent.attr('id'), success: function() { parent.slideUp(300,function() { parent.remove(); }); } }); }); </code></pre> <p>The data: <code>'id=' + parent.attr('id')</code> needs a extra <code>$php_var</code> sent to the URL: <code>server_items_reorder.php</code></p> <p>A little further down in my code I have:</p> <pre><code>function savelayout(){ var positions = ""; var weight = 0; var wb_name = "$wb_name"; $(".portlet").each(function(){weight++;positions+=(this.id + "=" + this.parentNode.id + "|" + weight + "&amp;");}); $.ajax({ type: "POST", url: "server_items_reorder.php", data: positions }); } </code></pre> <p>As you can see, I already tried there to add a <code>$var</code> called <code>wb_name</code>.</p> <p>Full code here:</p> <pre><code>/************************************************************************/ /* WB_BlocksManager v1.0 */ /* Module for phpnuke 6.x and 7.x by Paulo FERREIRA */ /* Copyright (C) 2003 Paulo Ferreira */ /* Web: http://www.phpnuke-belgique.org/ */ /* Email: webmaster@phpnuke-belgique.org */ /* =====================================================================*/ /* James Johnston */ /* http://www.techknowpro.com */ /* =====================================================================*/ /* nono */ /* http://osc2nuke.org/ */ /* =====================================================================*/ /* PHP-NUKE: Web Portal System */ /* =====================================================================*/ /* */ /* Copyright (c) 2002 by Francisco Burzi */ /* http://phpnuke.org */ /* */ /* This program is free software. You can redistribute it and/or modify */ /* it under the terms of the GNU General Public License as published by */ /* the Free Software Foundation; either version 2 of the License. */ /************************************************************************/ if (!defined('ADMIN_FILE')) { die('Access Denied'); } global $prefix, $db, $admin_file, $wb_name; $aid = substr($aid, 0, 25); $row = $db-&gt;sql_fetchrow($db-&gt;sql_query('SELECT radminsuper FROM ' . $prefix . '_authors WHERE aid=\'' . $aid . '\'')); if ($row['radminsuper'] == 1) { /*********************************************************/ /* Blocks_Manager Functions */ /*********************************************************/ function BlocksManager($wb_name) { global $db, $prefix, $currentlang, $multilingual, $bgcolor2, $admin_file; OpenHeader(_BLOCKMGR); $wb_url="".$admin_file.".php?op=BlocksManager&amp;amp;wb_name="; echo "&lt;center&gt;&lt;form action=\"".$admin_file.".php\" method=\"post\"&gt;\n" ._BLOCKMGR_MODULEDROP."&amp;nbsp;&lt;select name=\"wb_name\" size=\"1\" onChange=\"top.location.href=this.options[this.selectedIndex].value\"&gt;\n"; if (!isset($wb_name)) { $wb_name = "admin"; } echo "&lt;option value=\"".$wb_url."admin\""; if ($wb_name=="admin") { echo " selected"; } echo "&gt;Admin&lt;/option&gt;\n"; $result = $db-&gt;sql_query("SELECT mid, title, custom_title, active, view, inmenu FROM ".$prefix."_modules WHERE active=1 ORDER BY title ASC"); while(list($mid, $title, $custom_title, $active, $view, $inmenu) = $db-&gt;sql_fetchrow($result)) { echo "&lt;option value=\"".$wb_url.$title."\""; if ($wb_name==$title) { echo " selected"; } echo "&gt;$custom_title&lt;/option&gt;\n"; if (!isset($wb_name)) { $wb_name = $title; } } echo "&lt;/select&gt;\n" ."&lt;/form&gt;\n&lt;/center&gt;\n"; echo "&lt;br /&gt;&lt;br /&gt;"; echo "&lt;center&gt;&lt;b&gt;"._BLOCKMGR_ADDNEWBLOCK."&lt;/b&gt;&lt;/center&gt;\n" ."&lt;form name=\"BM_EDIT\" action=\"".$admin_file.".php\" method=\"post\"&gt;\n" ."&lt;table width=\"80%\" align=\"center\"&gt;\n" ."&lt;tr&gt;\n"; //List all inactive Blocks for selected module echo "&lt;td align=\"center\" valign=\"top\"&gt;\n" ._BLOCKMGR_ACTIVE_BLOCKS."&lt;br&gt;\n" ."&lt;select name=\"bida[]\" size=\"10\" multiple&gt;\n"; $sql = "SELECT bid, title FROM ".$prefix."_blocks ORDER BY title ASC"; $result = $db-&gt;sql_query($sql); while (list($bid, $title) = $db-&gt;sql_fetchrow($result)) { $ii = 0; $wb_affiche = 1; while ($ii &lt; $i) { if ($wb_tabblocks[$ii] == $bid) { $wb_affiche = 0; } $ii++; } if ($wb_affiche == 1) { echo "&lt;option value=\"".$bid."\"&gt;$title&lt;/option&gt;\n"; } } echo "&lt;/select&gt;&lt;br&gt;\n" ."&lt;input type=\"submit\" value=\""._BLOCKMGR_ADD_BLOCK."\" onclick=\"document.BM_EDIT.op.value='BlocksManager_Add';\"&gt;\n" ."&lt;/td&gt;\n"; //List all active Modules echo "&lt;td align=\"center\" valign=\"top\"&gt;" .""._BLOCKMGR_MODULES."&lt;br&gt;&lt;select name=\"title[]\" size=\"10\" multiple&gt;\n"; echo "&lt;option value=\"admin\""; if ($wb_name=="admin") { echo " selected"; } echo "&gt;Admin&lt;/option&gt;\n"; $sql = "SELECT mid, title, custom_title FROM ".$prefix."_modules WHERE active=1 ORDER BY title ASC"; $result = $db-&gt;sql_query($sql); while(list($mid, $title, $custom_title) = $db-&gt;sql_fetchrow($result)) { echo "&lt;option value=\"$title\""; if ($wb_name==$title) { echo " selected"; } echo "&gt;$custom_title&lt;/option&gt;\n"; if (!isset($wb_name)) { $wb_name = $title; } } echo "&lt;/select&gt;&lt;br&gt;" ."&lt;/td&gt;\n"; //List all active Blocks for selected module echo "&lt;td align=\"center\" valign=\"top\"&gt;\n" ._BLOCKMGR_INACTIVE_BLOCKS."&lt;br&gt;\n" ."&lt;select name=\"bidr[]\" size=\"10\" multiple&gt;\n"; $sql = "SELECT b.bid, b.title FROM ".$prefix."_blocks b, ".$prefix."_blocks_manager m WHERE b.bid=m.bid AND m.title='$wb_name' ORDER BY title ASC"; $result = $db-&gt;sql_query($sql); while(list($bid, $title) = $db-&gt;sql_fetchrow($result)) { echo "&lt;option value=\"$bid\"&gt;$title&lt;/option&gt;\n"; } echo "&lt;/select&gt;&lt;br&gt;\n" ."&lt;input type=\"submit\" value=\""._BLOCKMGR_REMOVE_BLOCK."\" onclick=\"document.BM_EDIT.op.value='BlocksManager_Remove';\"&gt;\n" ."&lt;/td&gt;\n" ."&lt;/tr&gt;\n" ."&lt;/table&gt;\n" ."&lt;input type=\"hidden\" name=\"wb_name\" value=\"$wb_name\"&gt;\n" ."&lt;input type=\"hidden\" name=\"op\" value=\"BlocksManager_Add\"&gt;\n" ."&lt;/form&gt;\n"; ?&gt; &lt;style type="text/css"&gt; body { font-size: 62.5%; } label, input { display:block; } input.text { margin-bottom:12px; width:95%; padding: .4em; } fieldset { padding:0; border:0; margin-top:25px; } h1 { font-size: 1.2em; margin: .6em 0; } div#users-contain { width: 350px; margin: 20px 0; } div#users-contain table { margin: 1em 0; border-collapse: collapse; width: 100%; } div#users-contain table td, div#users-contain table th { border: 1px solid #eee; padding: .6em 10px; text-align: left; } .ui-button { outline: 0; margin:0; padding: .4em 1em .5em; text-decoration:none; !important; cursor:pointer; position: relative; text-align: center; } .ui-dialog .ui-state-highlight, .ui-dialog .ui-state-error { padding: .3em; } .column { width: 170px; float: left; padding-bottom: 100px; } .portlet { margin: 0 1em 1em 0; } .portlet-header { margin: 0.3em; padding-bottom: 4px; padding-left: 0.2em; } .portlet-header .ui-icon { float: right; } .portlet-content { padding: 0.4em; } .ui-sortable-placeholder { border: 1px dotted black; visibility: visible !important; height: 50px !important; } .ui-sortable-placeholder * { visibility: hidden; } &lt;/style&gt; &lt;script type="text/javascript"&gt; $(function() { $(".column").sortable({ connectWith: '.column', update: savelayout }); $(".portlet").addClass("ui-widget ui-widget-content ui-helper-clearfix ui-corner-all delete") .find(".portlet-header") .addClass("ui-widget-header ui-corner-all") .prepend('&lt;span class="ui-icon ui-icon-wrench"&gt;&lt;/span&gt;') .prepend('&lt;span class="ui-icon ui-icon-plusthick"&gt;&lt;/span&gt;') .prepend('&lt;span class="ui-icon ui-icon-closethick"&gt;&lt;/span&gt;') .end() .find(".portlet-content").toggle(); $(".portlet-header .ui-icon-plusthick").toggle(function() { $(this).removeClass("ui-icon-plusthick"); $(this).addClass("ui-icon-minusthick"); $(this).parents(".portlet:first").find(".portlet-content").toggle(); }, function() { $(this).removeClass("ui-icon-minusthick"); $(this).addClass("ui-icon-plusthick"); $(this).parents(".portlet:first").find(".portlet-content").toggle(); } ); $('.ui-icon-closethick').click(function(e) { e.preventDefault(); var parent = $(this).parent().parent(); $.ajax({ type: "POST", url: "server_items_reorder.php", data: 'id=' + parent.attr('id'), success: function() { parent.slideUp(300,function() { parent.remove(); }); } }); }); $(".column").disableSelection(); }); &lt;/script&gt; &lt;div class="column" id="l"&gt; &lt;?php $sql = "SELECT b.bid, b.bkey, b.title, b.url, m.bposition, m.weight, b.active, b.blanguage, b.blockfile, b.view FROM ".$prefix."_blocks b, ".$prefix."_blocks_manager m WHERE b.bid=m.bid AND m.title='$wb_name' AND m.bposition = 'l' ORDER BY weight"; $result = $db-&gt;sql_query($sql); while(list($bid, $bkey, $title, $url, $bposition, $weight, $active, $blanguage, $blockfile, $view) = $db-&gt;sql_fetchrow($result)) { ?&gt; &lt;div class="portlet" id="&lt;?php echo $bid; ?&gt;"&gt; &lt;div class="portlet-header" id="&lt;?php echo $bid; ?&gt;"&gt;&lt;?php echo $title; ?&gt;&lt;/div&gt; &lt;div class="portlet-content"&gt;&lt;?php echo $title . '---(' . $view . ')'; ?&gt;&lt;/div&gt; &lt;/div&gt; &lt;?php } ?&gt; &lt;/div&gt; &lt;div class="column" id="c"&gt; &lt;?php $sql = "SELECT b.bid, b.bkey, b.title, b.url, m.bposition, m.weight, b.active, b.blanguage, b.blockfile, b.view FROM ".$prefix."_blocks b, ".$prefix."_blocks_manager m WHERE b.bid=m.bid AND m.title='$wb_name' AND m.bposition = 'c' ORDER BY weight"; $result = $db-&gt;sql_query($sql); while(list($bid, $bkey, $title, $url, $bposition, $weight, $active, $blanguage, $blockfile, $view) = $db-&gt;sql_fetchrow($result)) { ?&gt; &lt;div class="portlet" id="&lt;?php echo $bid; ?&gt;"&gt; &lt;div class="portlet-header"&gt;&lt;?php echo $title; ?&gt;&lt;/div&gt; &lt;div class="portlet-content"&gt;&lt;?php echo $title . '---(' . $bposition . '---' . $wb_name .')'; ?&gt;&lt;/div&gt; &lt;/div&gt; &lt;?php } ?&gt; &lt;/div&gt; &lt;div class="column" id="d"&gt; &lt;?php $sql = "SELECT b.bid, b.bkey, b.title, b.url, m.bposition, m.weight, b.active, b.blanguage, b.blockfile, b.view FROM ".$prefix."_blocks b, ".$prefix."_blocks_manager m WHERE b.bid=m.bid AND m.title='$wb_name' AND m.bposition = 'd' ORDER BY weight"; $result = $db-&gt;sql_query($sql); while(list($bid, $bkey, $title, $url, $bposition, $weight, $active, $blanguage, $blockfile, $view) = $db-&gt;sql_fetchrow($result)) { ?&gt; &lt;div class="portlet" id="&lt;?php echo $bid; ?&gt;"&gt; &lt;div class="portlet-header"&gt;&lt;?php echo $title; ?&gt;&lt;/div&gt; &lt;div class="portlet-content"&gt;&lt;?php echo $title . '---(' . $bposition . ')'; ?&gt;&lt;/div&gt; &lt;/div&gt; &lt;?php } ?&gt; &lt;/div&gt; &lt;div class="column" id="r"&gt; &lt;?php $sql = "SELECT b.bid, b.bkey, b.title, b.url, m.bposition, m.weight, b.active, b.blanguage, b.blockfile, b.view FROM ".$prefix."_blocks b, ".$prefix."_blocks_manager m WHERE b.bid=m.bid AND m.title='$wb_name' AND m.bposition = 'r' ORDER BY weight"; $result = $db-&gt;sql_query($sql); while(list($bid, $bkey, $title, $url, $bposition, $weight, $active, $blanguage, $blockfile, $view) = $db-&gt;sql_fetchrow($result)) { ?&gt; &lt;div class="portlet" id="&lt;?php echo $bid; ?&gt;"&gt; &lt;div class="portlet-header"&gt;&lt;?php echo $title; ?&gt;&lt;/div&gt; &lt;div class="portlet-content"&gt;&lt;?php echo $title . '---(' . $bposition . ')'; ?&gt;&lt;/div&gt; &lt;/div&gt; &lt;?php } ?&gt; &lt;/div&gt; &lt;script type="text/javascript"&gt; function savelayout(){ var positions = ""; var weight = 0; var wb_name = "$wb_name"; $(".portlet").each(function(){weight++;positions+=(this.id + "=" + this.parentNode.id + "|" + weight + "&amp;");}); $.ajax({ type: "POST", url: "server_items_reorder.php", data: positions }); } &lt;/script&gt; &lt;?php CloseFooter(); } function BlocksManager_Add($bid, $title) { global $db, $prefix; foreach($title as $tKey =&gt; $tValue) { $sql = "SELECT MAX(weight) FROM ".$prefix."_blocks_manager WHERE title='$tValue'"; $result = $db-&gt;sql_query($sql); list($weight, $bposition) = $db-&gt;sql_fetchrow($result); foreach($bid as $bKey =&gt; $bValue) { $weight++; $db-&gt;sql_query("INSERT INTO ".$prefix."_blocks_manager VALUES ($bValue, '$tValue', 'l', $weight)"); } BlocksManager_FixWeight($tValue); } } function BlocksManager_Remove($bid, $title) { global $db, $prefix; foreach($title as $tKey =&gt; $tValue) { foreach($bid as $bKey =&gt; $bValue) { $db-&gt;sql_query("DELETE FROM ".$prefix."_blocks_manager WHERE bid='$bValue' AND title='$tValue'"); } BlocksManager_FixWeight($tValue); } } function BlocksManager_FixWeight($wb_name) { global $db, $prefix; $position[] = 'l'; $position[] = 'r'; $position[] = 'c'; $position[] = 'd'; $position[] = ''; foreach($position as $pKey =&gt; $pValue) { $result = $db-&gt;sql_query("SELECT bid FROM ".$prefix."_blocks_manager WHERE title='$wb_name' AND bposition='$pValue' ORDER BY weight ASC"); $weight = 0; while(list($bid) = $db-&gt;sql_fetchrow($result)) { $weight++; if ($pValue != '') : $db-&gt;sql_query("UPDATE ".$prefix."_blocks_manager SET weight='$weight' WHERE title='$wb_name' AND bid='$bid'"); else : $db-&gt;sql_query("UPDATE ".$prefix."_blocks_manager SET weight='$weight', bposition='l' WHERE title='$wb_name' AND bid='$bid'&lt;br&gt;"); endif; } } } function BlocksManager_BlockPosition($bid, $wb_name, $position) { global $db, $prefix; $db-&gt;sql_query("UPDATE ".$prefix."_blocks_manager SET bposition='$position' WHERE bid='$bid' AND title='$wb_name'"); BlocksManager_FixWeight($wb_name); } function BlocksManager_BlockOrder($wb_name, $weightrep, $weight, $bidrep, $bidori) { global $db, $prefix; $result = $db-&gt;sql_query("UPDATE ".$prefix."_blocks_manager SET weight='$weight' WHERE bid='$bidrep'"); $result2 = $db-&gt;sql_query("UPDATE ".$prefix."_blocks_manager SET weight='$weightrep' WHERE bid='$bidori'"); BlocksManager_FixWeight($wb_name); } function OpenHeader($title="") { include("header.php"); GraphicAdmin(); title($title); OpenTable(); } function CloseFooter() { CloseTable(); include("footer.php"); } switch($op) { case "BlocksManager": BlocksManager($wb_name); break; case "BlocksManager_Add": BlocksManager_Add($bida, $title); Header("Location: ".$admin_file.".php?op=BlocksManager&amp;wb_name=$wb_name"); break; case "BlocksManager_Remove": BlocksManager_Remove($bidr, $title); Header("Location: ".$admin_file.".php?op=BlocksManager&amp;wb_name=$wb_name"); break; case "BlocksManager_BlockPosition": BlocksManager_BlockPosition($bid, $title, $position); Header("Location: ".$admin_file.".php?op=BlocksManager&amp;wb_name=$title"); break; case "BlocksManager_FixWeight": BlocksManager_FixWeight($wb_name); Header("Location: ".$admin_file.".php?op=BlocksManager&amp;wb_name=$wb_name"); break; case "BlocksManager_BlockOrder": BlocksManager_BlockOrder ($title, $weightrep, $weight, $bidrep, $bidori); Header("Location: ".$admin_file.".php?op=BlocksManager&amp;wb_name=$title"); break; } } else { echo "Access Denied"; } </code></pre> <p>The purpose of the code is to control a block system by modules. You can move/add/change/delete blocks by its module.</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.
    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