0

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 !

1
  • I don't understand your question. What is wrong? Commented Nov 5, 2009 at 0:21

3 Answers 3

2

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.

Sign up to request clarification or add additional context in comments.

2 Comments

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

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>';

2 Comments

Are you sure you're posting to the right URI? Inspect this in Firebug and see where its going.
in fact the get variable is : undefine !
1

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.

2 Comments

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 ?
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. docs.jquery.com/Ajax en.wikipedia.org/wiki/Ajax_(programming)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.