[英]jQuery - Pass variable to php
I'm very new to this and I've searched around all day today to get it working but I haven't managed to find a way to use a variable, only hard-coded values work. 我对此很陌生,今天整天都在进行搜索以使其正常工作,但是我还没有找到使用变量的方法,只有硬编码的值有效。 Here is my code with a hard-coded value: 这是我的带有硬编码值的代码:
<script type="text/javascript">
FB.Event.subscribe('edge.create',
function(response) {
$.post("http://www.my-domain.com/fbtest.php", { category: "845" } );
}
);
</script>
What I'd like to have is change that 845 value to a variable called $vpostid. 我想将845值更改为一个名为$ vpostid的变量。 When I change it to that it doesn't work, so I assume I need to get the double quotation marks around the number but I can't see to get the correct combination. 当我将其更改为不起作用时,因此我假设我需要在数字周围加上双引号,但是我看不到获得正确的组合。
I'm assuming you mean "pass variable from php": 我假设您的意思是“ 从 php传递变量”:
If short hand openings are enabled: 如果启用了短手打开:
<script type="text/javascript">
FB.Event.subscribe('edge.create',
function(response) {
$.post("http://www.my-domain.com/fbtest.php", { category: "<?=$vpostid?>" } );
}
);
</script>
else: 其他:
<script type="text/javascript">
FB.Event.subscribe('edge.create',
function(response) {
$.post("http://www.my-domain.com/fbtest.php", { category: "<?php echo $vpostid; ?>" } );
}
);
</script>
try this code: 试试这个代码:
<script type="text/javascript">
FB.Event.subscribe('edge.create',
function(response) {
$.post("http://www.my-domain.com/fbtest.php", { category: "<?php echo($vpostid); ?>" } );
}
);
</script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.