doulan8846 2011-10-13 12:25
浏览 59
已采纳

使用Jquery将URL变量传递给PHPExcel

I'm trying to pass URL variables to my PHPExcel PHP script, so that i can extract them in the script using the $_GET array.
The call to the PHPExcel script happens when a form (form1) button is pressed, and the variables are based on a second form (filters_form).

{filters_form is a general "filters" form that serves different scripts, for example filtering a JqGrid. meaning to say, it is separated from form1 for a reason. form1 is where i placed a button that calls the PHPExcel script, which also need to use the same filters that the filters_form provide}

Thus, I'm trying to use Jquery to call the PHPExcel script like that:

$(document).ready(function() {
  $('#form1').click(function() {
    var filters_form_serialized = $('#filters_form').serialize();
    var URL = 'PHPExcel_script.php?' + filters_form_serialized;
    $('#form1').attr('action', URL);
    $('#form1').submit();
  });
});

form1 is:

<form id="form1" action="" method="get" target="_blank">
 <button id="form_button" type="button"></button>
</form>

filter_form is:

<form id="filters_form">
 <input name="input1" type="checkbox" value="0" checked="checked" />
 <input name="input2" type="checkbox" value="1" checked="checked" />
</form>

The PHPExcel script indeed gets called, BUT the script doesn't recognize/gets any of the variables in the $_GET array, e.g.:

if(isset($_GET['input1']))
  {echo "TRUE";}
else
  {echo "FALSE";}

returns FALSE.
any thoughts why?
Thanks!

P.S. i've checked using alerts that the URL is encoded correctly; moreover the exact same url with same variables is recognized correctly using other scripts.

  • 写回答

2条回答 默认 最新

  • dosf40815 2011-10-13 12:55
    关注

    What you try to achieve might have seemed possible you, but it is not:

    The query parameters from the action attribute are dropped by your browser. I think that was not obvious to you.

    Luckily, you don't need that.

    Instead just set a new location:

    $(document).ready(function() {
      $('#form1').click(function() {
        var filters_form_serialized = $('#filters_form').serialize();
        var URL = 'PHPExcel_script.php?' + filters_form_serialized;
        window.location.href = 'http://your.host/and/path/to/' + URL;
      });
    });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器