开发者

Variable from JavaScript to PHP

开发者 https://www.devze.com 2022-12-10 17:12 出处:网络
Here is the code: $(\'#sousmenu a\').click (function (){ startSlideshow(<?php echo json_encode(glob(\"photos-\" .$_GET[\"folder\"]. \"/*.jpg\"));?>);

Here is the code:

    $('#sousmenu a').click (function (){
        startSlideshow(<?php echo json_encode(glob("photos-" .$_GET["folder"]. "/*.jpg"));?>);
        return false;
    });

The question is I like the HREF to change and get caught by PHP, now it doesn't do anything, but writing the ?folder=portraits works.

Here is the page.

**** Simpler ***** Maybe I am not clear, it happens sometimes!

I want the link href to be send to this PHP function,

开发者_如何转开发<?php echo json_encode(glob("photos-" .(i what the href link). "/*.jpg"));?> 

so clicking on the link animaux will send animaux to the glob() PHP function and will get all the .jpg files in the photos-animaux folder.

Clicking on the portraits will send the photo-portraits, etc.


If you want to modify the URL and have the added/changed variable picked by PHP interpreter you have to reload your page. Just altering the URL doesn't do anything because JS is executed after PHP processing.

If your site is on http://example.com and you wish a myparam with value test to be passed to PHP you should add something like this in your JS:

document.location = 'http://example.com?myparam=test';

This will reload your page adding a new param which can be accessed in PHP by simply using $_GET['myparam'] variable.

You may also want to consider using AJAX to dynamically changing the contents of your page without having to refresh the whole page, but that's a little bit more complicated.


Look at the source in your browser.

Php is server-side, and that means you need to use ajax or reload whole page to get a response.

There is a nice ajax part of tutorial on jquery website, after reading it you should be able to do what you want: http://docs.jquery.com/Tutorials:Getting_Started_with_jQuery#Rate_me:_Using_Ajax

0

精彩评论

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