简体   繁体   中英

Push javascript value in to php

I would like to push JavaScript value into php:

var temp =  $('#field_id').val().charAt(0);

temp returns values 1-4.

var value = "<?php echo $variable[   .....    ]['id'] ;        ?>";

how to insert instead .....

Its impossible, the main reason is that Php is rendered server side ( so before it arrives to the client computer), while JavaScript is rendered in the browser ( so in the client PC).

Depending from your requirement, you may use an ajax request to get the info and update the dom with javascript, or use GET or POST request with the js variable required so that PHP will have it before it renders the page.

If you wold give me more information, I may probably help you, but the question is not specific enough

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM