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 飞机曲面部件如机翼,壁板等具体的孔位模型
  • ¥15 vs2019中数据导出问题
  • ¥20 云服务Linux系统TCP-MSS值修改?
  • ¥20 关于#单片机#的问题:项目:使用模拟iic与ov2640通讯环境:F407问题:读取的ID号总是0xff,自己调了调发现在读从机数据时,SDA线上并未有信号变化(语言-c语言)
  • ¥20 怎么在stm32门禁成品上增加查询记录功能
  • ¥15 Source insight编写代码后使用CCS5.2版本import之后,代码跳到注释行里面
  • ¥50 NT4.0系统 STOP:0X0000007B
  • ¥15 想问一下stata17中这段代码哪里有问题呀
  • ¥15 flink cdc无法实时同步mysql数据
  • ¥100 有人会搭建GPT-J-6B框架吗?有偿