0

我正在尝试将搜索关键字存储到我的数据库中。在我的搜索词中,我正在使用 YouTube API 并搜索 YouTube 视频。

<input spellcheck="false" value="" id="searchBox" class="statusPlaying"><span id="searchTermKeyword">amisha patel</span>

为了在数据库中存储搜索词,我已经这样做了,但它不起作用。谁能告诉我如何在不刷新页面的情况下存储搜索词?

<form enctype="multipart/form-data" id="form1" name="form1" method="post" action="">
    <input type="text" name="title" class="statusPlaying" id="searchBox" value="" spellcheck="false">
    <span id="searchTermKeyword"></span>
</form>

这是我的实时链接|

4

2 回答 2

0

如果您只是想在不刷新页面的情况下存储数据,请使用 Ajax(使用或不使用 jQuery,这取决于您)。

请参阅此处的示例:http: //api.jquery.com/jQuery.ajax/

您可以使用:

$.ajax()
$.post()
$.get()
etc.
于 2012-12-21T11:34:29.057 回答
0

如果我理解正确,您想在不重新加载整个页面的情况下向您的服务器发送内容。因此,您需要使用 AJAX。建议从 jQuery Ajax 开始,因为它简单且经过良好测试:http ://api.jquery.com/jQuery.ajax/

基本上,在不提供所有细节的情况下,您需要:

  • 绑定到某个事件以触发发送(例如,输入元素上的“更改”)
  • 序列化表单数据(例如使用$.serialize() http://api.jquery.com/serialize/
  • $.ajax()打电话_
于 2012-12-21T11:33:06.357 回答