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 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大