获得在jQuery的一个错误,当我尝试自动保存表单字段与一个Ajax调用 [英] Getting an error in jQuery when I try to autosave a form field with an ajax call
问题描述
我试图让一个轨道表单字段3项目,自动保存,当它被改变。我试图用下面的jQuery的AJAX调用做到这一点:
I'm trying to get a form field in a rails 3 project to autosave when it is changed. I'm attempting to do this with the following jQuery ajax call:
$j("#list_" + <%= item.list_id.to_s %> + "_item_" + <%=item.id.to_s %>).live("change",
function(){
$j.ajax({
beforeSend: function(request) {
request.setRequestHeader("Accept", "text/javascript");
},
type: 'POST',
url: '<%= list_text_item_path(List.find(item.list_id), TextItem.find(item.id)) %>/update',
data: {
value: $j(this).val(),
id: '<%= item.id.to_s %>',
list_id: '<%= item.list_id.to_s %>'
},
success: function(){
alert("success");
}
});
});
每当文本框改变时,我收到以下错误jQuery的:
Whenever the text box is changed, I get the following error in jQuery:
(c.value || "").replace is not a function
这是在这两个jQuery的-1.5.min.js。我也有与jQuery-1.4.2.min.js同样的错误发生。 (我更新到1.5,看看是否能帮助什么。)
This is in both jQuery-1.5.min.js. I also had the same error happen with jQuery-1.4.2.min.js. (I updated to 1.5 to see if that would help anything.)
这是我要去哪里错了有什么想法? 非常感谢。
Any thoughts on where I'm going wrong? Thanks so much.
编辑:哦,废话,让我的HTML后,我意识到我有.live时()调用附加到表单输入元素的div容器,而不是表单输入元素本身。我有一个单独的问题,但我想我会后,一旦我找出可能导致它...
Oh crap, when getting my HTML to post I realized I had the .live() call attached to the form input element's container div and not the form input element itself. I'm having a separate issue but I guess I'll post that once I figure out what might be causing it...
推荐答案
唉,我想通了......一个不小心的错误。我曾在一个HTML列表项中输入元素,和我有.live()函数调用连接到李ID而不是输入元素的id。感谢以上球员的帮助。
Ugh, I figured it out... a careless error. I had the input element in a HTML list item, and I had the .live() function call attached to the li id rather than the input element id. Thanks for the help above guys.
这篇关于获得在jQuery的一个错误,当我尝试自动保存表单字段与一个Ajax调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!