开发者

Passing URL variables to PHPExcel with Jquery

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开发者_如何学JAVA_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.


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;
  });
});


I don't understand why don't you simply do:

<form id="the_form" action="PHPExcel_script.php" method="get" target="_blank">
 <input name="input1" type="checkbox" value="0" checked="checked" />
 <input name="input2" type="checkbox" value="1" checked="checked" />
 <button id="form_button" type="button"></button>
</form>

  $('#form_button').click(function() {
    $(this).submit();
  });

which should submit the form correctly. You were setting the action of the form with parameters. No need to serialize anything i think.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜