Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I assign javascript variable to php variable? With out submitting the form

hi friends can some one tell me How do I assign javascript variable to php variable? I am actually getting a value through javascript and I want the javascript values to be assigned to php variables. With out submitting the form.

like image 590
Jaguar Avatar asked Jan 22 '23 10:01

Jaguar


1 Answers

Unless you are doing something really esoteric (such as running server side JS and PHP):

The PHP runs, generates a response, sends it to the browser. If that response includes JavaScript then that JS will then be executed.

You can't get data from the JS back to the PHP without issuing a new HTTP request.

This could be done by setting document.location, adding an <img> element to the document with the data passed via the src attribute (in both cases including the data in a query string, posting a <form> to an <iframe>, using an XMLHttpRequest object and a host of other methods.

It really depends on what you want to achieve.

like image 71
Quentin Avatar answered Jan 29 '23 20:01

Quentin