【问题标题】:How to Display plain text of api result ( noob question )如何显示 api 结果的纯文本(菜鸟问题)
【发布时间】:2021-10-28 10:43:39
【问题描述】:

我对 api 完全陌生。 我想显示这个输出的纯文本响应:

https://vurl.com/api.php?url=https://google.com

到我的网页 html 但它不起作用。

我的代码:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>

$url = urlencode('https://google.com');
$api_url = 'vurl.com/api.php?url='.$url;
$arr_output = json_decode(file_get_contents($api_url), true);
document.write($arr_output);
</script>

谢谢

【问题讨论】:

  • 不要将 PHP 与 JavaScript 混合使用。在 JS 中,连接运算符不是.,而是加号+。此外,在创建变量之前不需要美元符号

标签: javascript php api


【解决方案1】:

不太清楚为什么要将javascriptphp 代码混合使用。不过,这是您应该遵循的方法:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>

<?php
$url = urlencode("https://google.com");
$api_url = "vurl.com/api.php?url=".$url;
$arr_output = json_decode(file_get_contents($api_url), true);

echo $arr_output;
?>

</script>

【讨论】:

  • 非常感谢!我想我需要休息一下。 google.com"); $api_url = "vurl.com/api.php?url=".$url;回显文件获取内容($api_url); ?>
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-02-08
  • 2017-07-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-10-24
相关资源
最近更新 更多