Reputation: 516
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");
}
});
});
Whenever the text box is changed, I get the following error in jQuery:
(c.value || "").replace is not a function
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.
Edit: 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...
Upvotes: 4
Views: 335
Reputation: 516
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.
Upvotes: 1