gpt4 book ai didi

javascript - 如何将 php 变量添加到 javascript 中?

转载 作者:行者123 更新时间:2023-11-28 11:34:37 25 4
gpt4 key购买 nike

这是我的代码:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
<?php
$url = "http://api.wunderground.com/api/7d5339867b063fd0/geolookup/conditions/q/UK/".$area.".json";
?>

<script>

jQuery(document).ready(function($) {
$.ajax({
url : ,
dataType : "jsonp",
success : function(parsed_json) {
var location = parsed_json['location']['city'];
var temp_f = parsed_json['current_observation']['temp_f'];
alert("This is an example of a web service outputting using Json. The current temperature in " + location + " is: " + temp_f);
}
});
});

</script>

如何将“$url”变量添加到位于“url : “here”的 JavaScript 代码中,

谢谢

最佳答案

你只需要这样说:

url : "<?=$url?>",

或(最好的方法):

url : "<?php echo $url; ?>",

关于javascript - 如何将 php 变量添加到 javascript 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26865989/

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