gpt4 book ai didi

javascript - 如何将此 observe_field 转换为 jquery

转载 作者:行者123 更新时间:2023-11-29 22:35:08 25 4
gpt4 key购买 nike

我想使用 jquery 而不是 prototype 并且我有点迷失在 jquery 中转换这个 observe_field。

<%=text_field_tag :section %>
<%= observe_field(:section,
:frequency => 0.1,
:update => "article_list",
:with => 'section',
:url =>{ :action => :get_article_list }) %>

这是我的开始:

$(document).ready(function() {
$("#section").bind("keyup", function() {
var url = '/catalogs/get_article_list';
$.get(url, function(html) {
$("#article_list").html(html);
});
});
});

我读了这个post但我想我错过了一些东西。

将不胜感激任何解释。

谢谢。

最佳答案

观察者,观察任何输入元素上的事件,当事件发生时,它使用 ajax 向给定的 url 发送请求,并在给定元素的页面上更新响应。

这里事件监听的很好,所以你写了绑定(bind)section元素的keyup事件的代码。

现在,当 keyup 事件触发时,您需要向服务器发出 ajax 请求。

 $(document).ready(function() {
$("#section").bind("keyup", function() {
data = {this.name: this.val()}; // the value of input that need to send to server
$.get(url, data, // make ajax request
function(html) { // function to handle the response
$("#article_list").html(html); // change the inner html of update div
});
});
});

希望这能帮助你理解它。

关于javascript - 如何将此 observe_field 转换为 jquery,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5447722/

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