0

I have to send a value that is stored in a JavaScript variable to a PHP page. The PHP page is in a different folder than the JavaScript page.

This JavaScript variable is in a method that fires when we click a button.

How can I send that variable value to the PHP page?

(This is an Eclipse project.)

user2428118
8,1344 gold badges47 silver badges74 bronze badges
asked Jul 11, 2011 at 5:14

3 Answers 3

4

The easiest way to do this is to use jQuery's POST method to send serialized data to a PHP page that can process your request.

However, you didn't say if you want the client to cache the value and always remind server of the value for all future requests. If so, you can once again use JavaScript to store values inside the cookie, so that every time user click on something (GET / POST) it will also send out the cookie containing your javascript value to the server

answered Jul 11, 2011 at 5:27
Sign up to request clarification or add additional context in comments.

2 Comments

as I think your reply is the most helpful answer.but I in this site they are using mootools.so using jquery is a conflict.isn't it?is it possible to do this using mootools also?
You can certainly do this with mootool mootools.net/docs/core/Request/Request.HTML
1

Using Ajax

answered Jul 11, 2011 at 5:17

Comments

1

Do you submit a HTML form when the button is clicked. If yes then you can set the javascript variable value into a hidden field of the form on button click. After which your PHP code and read its value on the server-side.

answered Jul 11, 2011 at 5:24

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.