Skip to content Skip to sidebar Skip to footer

Variable From Javascript To Php

Here is the code: $('#sousmenu a').click (function (){ startSlideshow(); return false

Solution 1:

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.

Solution 2:

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

Post a Comment for "Variable From Javascript To Php"