douhuai2861 2013-04-18 21:46
浏览 45
已采纳

如何将大量参数从PHP传递到Javascript函数?

I'm developing a Joomla module, with several parameters to define how it works. I have buttons in the module area, and buttons have to interact with those parameters. Here is the module PHP code:

<?php
defined('_JEXEC') or die('Direct Access to this location is not allowed.');
$AdVisualV2jMODPHP_ver='0.3.0070';
$Station_ID = $params->get('Station_ID');
$Verbose = $params->get('Verbose');
$Bk_ColorODD = $params->get('Bk_ColorODD');
$Bk_ColorEVEN = $params->get('Bk_ColorEVEN');
$Ink_ColorODD = $params->get('Ink_ColorODD');
$Ink_ColorEVEN = $params->get('Ink_ColorEVEN');
$PicCol_Title = $params->get('PicCol_Title');
$TxtCol_Title = $params->get('TxtCol_Title');
$EvPic_Heightpx = $params->get('EvPic_Heightpx');
$EvPic_Widhtpx = $params->get('EvPic_Widhtpx');
$CatPic_Heightpx = $params->get('CatPic_Heightpx');
$CatPic_Widhtpx = $params->get('CatPic_Widhtpx');
$Pic_Hspanpx = $params->get('Pic_Hspanpx');
$Pic_Vspanpx = $params->get('Pic_Vspanpx');
$TitleSw = $params->get('TitleSw');
$MenuPos = $params->get('MenuPos');
$Paging = $params->get('Paging');
$Sort_Field = $params->get('Sort_Field');
$Sort_Order = $params->get('Sort_Order');
$db_host = "localhost";
$db_user = "xxxx";
$db_database = "xxxxx";
$db_password = "xxxxx";
$db_tabconfig = "xxxxxxx";
$db_tabpreroll = "xxxxxxxxxxx";

echo 'AVVIAMO LA PROCEDURA 0.0.090 - '.$Station_ID.'<br><br>';
echo '<div id="TabellaEventi"></div>';
echo '<INPUT Type="BUTTON" VALUE="Avanti" ONCLICK="avanti()"> ';
echo '<INPUT Type="BUTTON" VALUE="Indietro" ONCLICK="indietro()"> ';
echo '<br>';
?>

When the user will click on the "Avanti" or "Indietro" buttons i call the JAVASCRIPT functions avanti() and indietro(), and those two functions will work with ALL the parameters above. How can I do to transfer this huge amount of variables?

AND!!! The two Javascript functions will have to call OTHER PHP files to interact with a MySql database, and again i will need more or less ALL the variables in the other file.

Internet programming is such a mess sometime...

  • 写回答

2条回答 默认 最新

  • donglu3087 2013-04-18 22:38
    关注

    Ajax might not needed. Put all your variable in a big array of data

    $data['Station_ID'] = $params->get('Station_ID');
    $data['Verbose'] = $params->get('Verbose');
    ...
    
    $data = json_encode($data);
    $data = htmlentities($data);
    ...
    echo '<INPUT Type="BUTTON" VALUE="Avanti" ONCLICK="avanti(' . $data . ')"> ';
    

    Now avanti contains an JSON object as 1st parameter

    Edit: because the JSON string might contain " and < you must call htmlentities to protect your string

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 win10权限管理,限制普通用户使用删除功能
  • ¥15 minnio内存占用过大,内存没被回收(Windows环境)
  • ¥65 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案
  • ¥50 yalmip+Gurobi
  • ¥20 win10修改放大文本以及缩放与布局后蓝屏无法正常进入桌面
  • ¥15 itunes恢复数据最后一步发生错误