在 HTML 中使用 API - 如何发送 API 数据并在我的 iframe 中显示其响应?

问题描述 投票:0回答:1

这是我的一个较新的 html 项目中的一段代码:

<form action='https://www.Bing.com/' method='PUT'>
  <div>
    <label for='newTab'>New Tab?</label>
    <input type='checkbox' name='newTab' id='newTab'/>
  </div>
  <div>
    <label for='newTab'>What do you want to search?</label>
    <input name='/search?q=' id='/search?q=' value='Shopping' />
  </div>
  <div>
    <button>Search</button>
  </div>
</form>

它应该做的是与 Bing API 交互并返回指定的搜索 - 例如这里我想生成“购物”搜索,我从 Bing API 中获取了两个值 - 'newTab' 值和 '/ search?q' 值来发送信息,但是当我发送信息时,它不是显示带有“购物”的搜索栏,而是显示 Bing 主页。

正如您可能知道的那样,我对使用 API 完全陌生,尤其是在 HTML 中——有人可以帮我调试这个吗?

html iframe put bing
1个回答
0
投票

假设您的表单位于 iframe 内,这应该可以解决问题。

<form action='https://www.Bing.com/search' method='GET'>
  <div>
    <label for='newTab'>New Tab?</label>
    <input type='checkbox' name='newTab' id='newTab'/>
  </div>
  <div>
    <label for='search'>What do you want to search?</label>
    <input name='q' id='search' value='Shopping' />
  </div>
  <div>
    <button>Search</button>
  </div>
</form>

您还可以在这里阅读一些文档:https://www.w3schools.com/tags/att_form_method.asp

© www.soinside.com 2019 - 2024. All rights reserved.