0

I have the following:

var model='ABCD';
var from = '4/12/2016';
var to ='4/12/2017';
var line= 'A';

window.location = "data/export.php?model="+model+"&from="+from+"&to="+to+"&line="+line;

now I am trying to access these variables in export.PHP so I can use them in a query. Is that possible? I have been looking around and reading but it looks like it isn't?

I have tried doing:

$fromDate = $_GET['from '];
$toDate = $_GET['to'];
$line= $_GET['line']; 
...

I think this doesn't work because it is not sending them in GET but is there a way to access those in PHP?

I understand I could use ajax but there is a limitation because of a library that I am using that won't work with ajax calls so there was the suggestion to use window. location=URL is there something similar to this method that would allow me to access the variables from JS to PHP and then work with a spout download xlsx file?

I am really new to programming so I apologize if this is obvious.

cocopan
  • 109
  • 3
  • 19
  • 1
    Have you tried using `window.location.href`? `window.location.href = "data/export.php?model="+model+"&from="+from+"&to="+to+"&line="+line` – Lixus Apr 12 '17 at 22:59
  • I have and same behavior @lixus – cocopan Apr 12 '17 at 23:30
  • 1
    from's $_GET has a space, it should be $_GET['from'] – Emad Salah Apr 12 '17 at 23:38
  • 1
    @cocopan How about `window.location.replace(url)`? – Lixus Apr 12 '17 at 23:41
  • 1
    Yes, window.location or window.location.href are both acceptable and they each produce a GET request. What directory are you running the javascript in? In "data" or another directory? Also in your PHP script do you have error_reporting on. If so what error message(s) do you see. I ran your javascript on my own box and created a PHP file in the same directory and the two worked perfectly. – slevy1 Apr 12 '17 at 23:51
  • Thank you, you are all correct. I had read other posts that confused me a lot (http://stackoverflow.com/questions/1917576/how-to-pass-javascript-variables-to-php). I tried it and it looks like I have a join that is making the values not get to the query. I am using a download method so there is no error reporting it either triggers the download or not but I think I found a way to bedbug it now. I appreciate all of your help!! sorry I took your time with something so simple! – cocopan Apr 13 '17 at 13:59

0 Answers0