admin管理员组文章数量:1418140
Passing value JavaScript variable to PHP.
Example
JavaScript
Var ddd='aaaa'
PHP
if (ddd="aaaa"){do somehting...}
Passing value JavaScript variable to PHP.
Example
JavaScript
Var ddd='aaaa'
PHP
if (ddd="aaaa"){do somehting...}
Share
Improve this question
edited Jan 14, 2016 at 10:43
Adam Azad
11.3k5 gold badges31 silver badges72 bronze badges
asked May 23, 2011 at 3:30
user730815user730815
532 silver badges6 bronze badges
3
- 2 What are you asking exactly? You could submit a form or make an ajax request... – no.good.at.coding Commented May 23, 2011 at 3:36
- I would do an ajax request here. – webdad3 Commented May 23, 2011 at 3:39
- Could you pass it in the URL to the PHP code, an ajax post to domain./?ddd=aaaa A code example would be good! – addedlovely Commented May 23, 2011 at 3:48
4 Answers
Reset to default 4Javascript is a Client side scripting language that is only executed after the page is fully loaded. PHP on the other hand is an on-demand piling script. It parses the PHP within the file and outputs the resulting HTML to the user's Browser.
In JS:
$.post('ajax.php',{'dddd' : dddd}, function(data){
});
In PHP
if(isset($_POST['dddd'])) $dddd = $_POST['dddd'];
One way you can do that is to put it in the cookie:
var ddd = 'aaaa';
document.cookie = "ddd="+ddd; // the ddd in the "" is the name of the cookie
PHP
$ddd = $_COOKIE['ddd'];
if (ddd == "aaa") { do something... }
I have tested the following code and it have worked. So please test this code:
function aa()
{
var ddd='aaaa';
window.location.href="newpage.php?Result=" +ddd;
}
click a button then will call aa()
function and will go newpage.php where we get ddd variable value in Result variable
newpage.php:
extract($_GET);
echo $Result;
本文标签: How to pass value JavaScript variable to PHPStack Overflow
版权声明:本文标题:How to pass value JavaScript variable to PHP? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745278841a2651325.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论