tags:

views:

58

answers:

3

That code work:

startSlideshow(<?php echo json_encode(glob("photos-animaux/*.jpg"))?>);

that code dont :

$.post("",{'folder':'animaux'});
startSlideshow(<?php echo json_encode(glob("photos-".$_GET["folder"]."/*.jpg"))?>);

WHY ?, what i am doing wrong ?, help ! why the stupid php fonction just dont make the string right !! ahhhh!

---new infos---- that line work :

startSlideshow(<?php echo json_encode(glob("photos-".$_GET["folder"]."/*.jpg")) ?>);

because if i MANUALLY enter in the address bar ?folder=animaux...bam! work

so the problem shoul be there : $.get("photo-portfolio.php",{folder:"animaux"});

still dont know where !

+2  A: 

If you're using $.post() from JQuery, you should use $_POST['folder'] to access your variable. If you use $.get(), then you use $_GET['folder'] in PHP. Try changing that $_GET to $_POST.

Travis
i change it .... still dont work, but i think the problem is the jquery part.... because when manually enter ?folder=animaux.. it work
marc-andre menard
If ?folder=animaux works, this is a fine way to do it. The preferred notation in JQuery for that though is $.get("",{'folder':'animaux'})
Travis
+1  A: 

Change $_GET["folder"] to $_POST["folder"] ?

You can dump the $_POST to be sure you're getting the right info..

echo '<pre>', print_r( $_POST, 1), '</pre>';
meder
try it, make sense, dont work !
marc-andre menard
post variable EMPTY
marc-andre menard
Are you sure you're posting to the right URI? Inspect this in Firebug and see where its going.
meder
how can i check ?
marc-andre menard
in fact the get variable is : undefine !
marc-andre menard
+1  A: 

I hope you're not literally writing these two lines together and hope they are interacting, are you?

$.post("",{'folder':'animaux'});
startSlideshow(<?php echo json_encode(glob("photos-".$_GET["folder"]."/*.jpg"))?>);

PHP runs on the server, Javascript in the browser. In the above two lines, if written like this, the PHP is already long done by the time $.post() is called.

PHP processes the code on the server and sends this to the browser:

$.post("",{'folder':'animaux'});
startSlideshow(['something.jpg', 'something2.jpg']);

The browser executes this code:

  1. Post {'folder':animaux'} to "" (no effect whatsoever).
  2. Start a slideshow with ['something.jpg', 'something2.jpg'] (which was already decided by the time the page loaded).

I hope you're aware of this two stage process.

deceze
So, what you explain to me make perfect sense, so that bring the question to me, how do i execute a javascript funtion, that send var to php on run time ?
marc-andre menard
Do you really need to send the variable at runtime? Is it based on any user input? Or could everything be prepared already before the page loads? If you *do* need to talk to the server during runtime, you'll need to send an AJAX request to the server which will answer with a JSON or XML object which you can use in your Javascript. http://docs.jquery.com/Ajax http://en.wikipedia.org/wiki/Ajax_(programming)
deceze