how to pass javascript jQuery variable value in php array
-
For example var dirnm = jQuery.trim($('#dirname').val()); var parent1 = jQuery.trim($('#parent').val()); var url = '<?=$this->url(array('controller'=>'index','action'=>'dirnameex','dirname'=>dirnm ,'parent'=>parent1))?>'; dirnm and parent1 are a ajax variables. So I want to pass dirnm and parent1 to a php array.
-
Answer:
This wont work as JavaScript is executed in the browser and PHP executed on the server .. so the PHP would be executed before the page is loaded in the browser and the JavaScript executed .... What you could do is POST the variables to PHP : var dirnm = jQuery.trim($('#dirname').val()); var parent1 = jQuery.trim($('#parent').val()); $.post("sript.php", { dirname: dirnm, parent: parent1 } ); then in PHP (script.php) : // get the variables from $_POST $dir = $_POST['dirname']; $par = $_POST['parent']; $this->url(array('controller'=>'index','action'=>'dirnameex','dirname'=> $dir,'parent'=> $par)) http://api.jquery.com/jQuery.post/ and http://php.net/manual/en/reserved.variables.post.php
user1312776 at Stack Overflow Visit the source
Other answers
php runs server side, javascript runs client side so you can't do that. You can pass the variables to php using ajax. but this would be a seperate thread.
encodes
Related Q & A:
- how to use javascript variable value in jsp?Best solution by Stack Overflow
- How to pass a variable from php to a modal?Best solution by Stack Overflow
- How to get JavaScript value in PHP?Best solution by Stack Overflow
- How to get Javascript array length?Best solution by Stack Overflow
- How to pass the value from the javascript to servlet?Best solution by Stack Overflow
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.