gpt4 book ai didi

php - 将js变量传递给php字符串

转载 作者:可可西里 更新时间:2023-11-01 01:06:03 25 4
gpt4 key购买 nike

我需要一些帮助,我正在尝试将一个 js 变量分页到一个正在使用 file_get_contents 在 php 中解析的 url。我不确定从哪里开始这样做。

<script type="text/javascript">
var js_variable = appl+goog+fb+mfst+nflx;
</script>

<?php
$ticker = js_varable_here;
$file = file_get_contents('http://finance.yahoo.com/d/quotes.csv?s=$ticker&f=soac1p2ghjkj1re');

?>

如有任何建议,我将不胜感激,就像我在这方面所说的那样。

最佳答案

这是一个使用 jquery 的例子。

Javascript:

<script type="text/javascript">
var js_variable = appl+goog+fb+mfst+nflx;
$.post("/somephp.php", {ticker: js_variable}, function(data) {
// returned from php
});
</script>

PHP:

 <?php
$ticker = $_POST['ticker'];
$file = file_get_contents("http://finance.yahoo.com/d/quotes.csv?s=$ticker&f=soac1p2ghjkj1re");
?>

关于php - 将js变量传递给php字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10761815/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com