2010-01-06 45 views
0

我正嘗試使用jQuery將額外的$php_var發送到Ajax post函數。 在第1 $.ajax我:使用PHP/jQuery UI將額外的數據值發送到ajax.php文件

$('.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(); 
      }); 
     } 
    }); 
}); 

數據:'id=' + parent.attr('id')需要發送到URL中的額外$php_varserver_items_reorder.php

再往在我的代碼下來,我有:

function savelayout(){ 
var positions = ""; 
var weight = 0; 
var wb_name = "$wb_name"; 
$(".portlet").each(function(){weight++;positions+=(this.id + "=" + this.parentNode.id + "|" + weight + "&");}); 

$.ajax({ 
type: "POST", 
url: "server_items_reorder.php", 
data: positions 
}); 
} 

正如你所看到的,我已經在那裏嘗試添加一個名爲wb_name$var

全部代碼在這裏:

/************************************************************************/ 
/* 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: [email protected]        */ 
/* =====================================================================*/ 
/* 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->sql_fetchrow($db->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&wb_name="; 
    echo "<center><form action=\"".$admin_file.".php\" method=\"post\">\n" 
     ._BLOCKMGR_MODULEDROP."&nbsp;<select name=\"wb_name\" size=\"1\" onChange=\"top.location.href=this.options[this.selectedIndex].value\">\n"; 
    if (!isset($wb_name)) { $wb_name = "admin"; } 
    echo "<option value=\"".$wb_url."admin\""; if ($wb_name=="admin") { echo " selected"; } echo ">Admin</option>\n"; 
    $result = $db->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->sql_fetchrow($result)) { 
     echo "<option value=\"".$wb_url.$title."\""; if ($wb_name==$title) { echo " selected"; } echo ">$custom_title</option>\n"; 
     if (!isset($wb_name)) { $wb_name = $title; } 
    } 
    echo "</select>\n" 
     ."</form>\n</center>\n"; 






    echo "<br /><br />"; 

    echo "<center><b>"._BLOCKMGR_ADDNEWBLOCK."</b></center>\n" 
     ."<form name=\"BM_EDIT\" action=\"".$admin_file.".php\" method=\"post\">\n" 
     ."<table width=\"80%\" align=\"center\">\n" 
     ."<tr>\n"; 
    //List all inactive Blocks for selected module 
    echo "<td align=\"center\" valign=\"top\">\n" 
     ._BLOCKMGR_ACTIVE_BLOCKS."<br>\n" 
     ."<select name=\"bida[]\" size=\"10\" multiple>\n"; 
    $sql = "SELECT bid, title FROM ".$prefix."_blocks ORDER BY title ASC"; 
    $result = $db->sql_query($sql); 
    while (list($bid, $title) = $db->sql_fetchrow($result)) { 
     $ii = 0; $wb_affiche = 1; 
     while ($ii < $i) { if ($wb_tabblocks[$ii] == $bid) { $wb_affiche = 0; } $ii++; } 
     if ($wb_affiche == 1) { echo "<option value=\"".$bid."\">$title</option>\n"; } 
    } 
    echo "</select><br>\n" 
     ."<input type=\"submit\" value=\""._BLOCKMGR_ADD_BLOCK."\" onclick=\"document.BM_EDIT.op.value='BlocksManager_Add';\">\n" 
     ."</td>\n"; 

    //List all active Modules 
    echo "<td align=\"center\" valign=\"top\">" 
     .""._BLOCKMGR_MODULES."<br><select name=\"title[]\" size=\"10\" multiple>\n"; 
    echo "<option value=\"admin\""; if ($wb_name=="admin") { echo " selected"; } echo ">Admin</option>\n"; 
    $sql = "SELECT mid, title, custom_title FROM ".$prefix."_modules WHERE active=1 ORDER BY title ASC"; 
    $result = $db->sql_query($sql); 
    while(list($mid, $title, $custom_title) = $db->sql_fetchrow($result)) { 
     echo "<option value=\"$title\""; 
     if ($wb_name==$title) { echo " selected"; } 
     echo ">$custom_title</option>\n"; 
     if (!isset($wb_name)) { $wb_name = $title; } 
    } 
    echo "</select><br>" 
     ."</td>\n"; 

    //List all active Blocks for selected module 
    echo "<td align=\"center\" valign=\"top\">\n" 
     ._BLOCKMGR_INACTIVE_BLOCKS."<br>\n" 
     ."<select name=\"bidr[]\" size=\"10\" multiple>\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->sql_query($sql); 
    while(list($bid, $title) = $db->sql_fetchrow($result)) { 
     echo "<option value=\"$bid\">$title</option>\n"; 
    } 
    echo "</select><br>\n" 
     ."<input type=\"submit\" value=\""._BLOCKMGR_REMOVE_BLOCK."\" onclick=\"document.BM_EDIT.op.value='BlocksManager_Remove';\">\n" 
     ."</td>\n" 
     ."</tr>\n" 
     ."</table>\n" 
     ."<input type=\"hidden\" name=\"wb_name\" value=\"$wb_name\">\n" 
     ."<input type=\"hidden\" name=\"op\" value=\"BlocksManager_Add\">\n" 
     ."</form>\n"; 

?> 








<style type="text/css"> 
     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; } 

    </style> 
    <script type="text/javascript"> 




$(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('<span class="ui-icon ui-icon-wrench"></span>') 
       .prepend('<span class="ui-icon ui-icon-plusthick"></span>') 
       .prepend('<span class="ui-icon ui-icon-closethick"></span>') 
      .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(); 
    }); 
    </script> 

<div class="column" id="l"> 
<?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->sql_query($sql); 
    while(list($bid, $bkey, $title, $url, $bposition, $weight, $active, $blanguage, $blockfile, $view) = $db->sql_fetchrow($result)) { 

?> 
    <div class="portlet" id="<?php echo $bid; ?>"> 
     <div class="portlet-header" id="<?php echo $bid; ?>"><?php echo $title; ?></div> 
     <div class="portlet-content"><?php echo $title . '---(' . $view . ')'; ?></div> 
    </div> 
<?php 
} 
?> 

</div> 

<div class="column" id="c"> 
<?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->sql_query($sql); 
    while(list($bid, $bkey, $title, $url, $bposition, $weight, $active, $blanguage, $blockfile, $view) = $db->sql_fetchrow($result)) { 

?> 
    <div class="portlet" id="<?php echo $bid; ?>"> 
     <div class="portlet-header"><?php echo $title; ?></div> 
     <div class="portlet-content"><?php echo $title . '---(' . $bposition . '---' . $wb_name .')'; ?></div> 
    </div> 
<?php 
} 
?> 


</div> 

<div class="column" id="d"> 
<?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->sql_query($sql); 
    while(list($bid, $bkey, $title, $url, $bposition, $weight, $active, $blanguage, $blockfile, $view) = $db->sql_fetchrow($result)) { 

?> 
    <div class="portlet" id="<?php echo $bid; ?>"> 
     <div class="portlet-header"><?php echo $title; ?></div> 
     <div class="portlet-content"><?php echo $title . '---(' . $bposition . ')'; ?></div> 
    </div> 
<?php 
} 
?> 


</div> 

<div class="column" id="r"> 
<?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->sql_query($sql); 
    while(list($bid, $bkey, $title, $url, $bposition, $weight, $active, $blanguage, $blockfile, $view) = $db->sql_fetchrow($result)) { 

?> 
    <div class="portlet" id="<?php echo $bid; ?>"> 
     <div class="portlet-header"><?php echo $title; ?></div> 
     <div class="portlet-content"><?php echo $title . '---(' . $bposition . ')'; ?></div> 
    </div> 
<?php 
} 
?> 


</div> 
<script type="text/javascript"> 
function savelayout(){ 
var positions = ""; 
var weight = 0; 
var wb_name = "$wb_name"; 
$(".portlet").each(function(){weight++;positions+=(this.id + "=" + this.parentNode.id + "|" + weight + "&");}); 

$.ajax({ 
type: "POST", 
url: "server_items_reorder.php", 
data: positions 
}); 
} 
</script> 


<?php 


    CloseFooter(); 
} 

function BlocksManager_Add($bid, $title) { 
    global $db, $prefix; 

    foreach($title as $tKey => $tValue) { 
     $sql = "SELECT MAX(weight) FROM ".$prefix."_blocks_manager WHERE title='$tValue'"; 
     $result = $db->sql_query($sql); 
     list($weight, $bposition) = $db->sql_fetchrow($result); 
     foreach($bid as $bKey => $bValue) { 
      $weight++; 
      $db->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 => $tValue) { 
     foreach($bid as $bKey => $bValue) { 
      $db->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 => $pValue) { 
     $result = $db->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->sql_fetchrow($result)) { 
      $weight++; 
      if ($pValue != '') : $db->sql_query("UPDATE ".$prefix."_blocks_manager SET weight='$weight' WHERE title='$wb_name' AND bid='$bid'"); 
      else : $db->sql_query("UPDATE ".$prefix."_blocks_manager SET weight='$weight', bposition='l' WHERE title='$wb_name' AND bid='$bid'<br>"); 
      endif; 
     } 
    } 
} 

function BlocksManager_BlockPosition($bid, $wb_name, $position) { 
    global $db, $prefix; 
    $db->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->sql_query("UPDATE ".$prefix."_blocks_manager SET weight='$weight' WHERE bid='$bidrep'"); 
    $result2 = $db->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&wb_name=$wb_name"); 
    break; 

    case "BlocksManager_Remove": 
    BlocksManager_Remove($bidr, $title); 
    Header("Location: ".$admin_file.".php?op=BlocksManager&wb_name=$wb_name"); 
    break; 

    case "BlocksManager_BlockPosition": 
    BlocksManager_BlockPosition($bid, $title, $position); 
    Header("Location: ".$admin_file.".php?op=BlocksManager&wb_name=$title"); 
    break; 

    case "BlocksManager_FixWeight": 
    BlocksManager_FixWeight($wb_name); 
    Header("Location: ".$admin_file.".php?op=BlocksManager&wb_name=$wb_name"); 
    break; 

    case "BlocksManager_BlockOrder": 
    BlocksManager_BlockOrder ($title, $weightrep, $weight, $bidrep, $bidori); 
    Header("Location: ".$admin_file.".php?op=BlocksManager&wb_name=$title"); 
    break; 
} 

} else { 
    echo "Access Denied"; 
} 

代碼的目的是通過模塊來控制一個塊系統。您可以通過其模塊移動/添加/更改/刪除塊。

回答

0

你需要與你的AJAX請求搭配你的PHP在線:

$('.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') + '&php_var=<?php echo $php_var; ?>', 
     success: function() { 
      parent.slideUp(300,function() { 
       parent.remove(); 
      }); 
     } 
    }); 
}); 

併爲您的第二個例子:

function savelayout(){ 
    var positions = ""; 
    var weight = 0; 
    var wb_name = "<?php echo $wb_name; ?>"; 
    $(".portlet").each(function(){ 
     weight++; 
     positions += (this.id + "=" + this.parentNode.id + "|" + weight + "&"); 
    }); 

    $.ajax({ 
     type: "POST", 
     url: "server_items_reorder.php", 
     data: positions 
    }); 
} 
0

你的意思

$.ajax({ 
    type: "POST", 
    url: "server_items_reorder.php", 
    data: {'positions':positions, 'wb_name': wb_name} 
}); 

相關問題