Getting error in jQuery when I try to autosave form field using ajax call

I am trying to get a form field in a rails 3 project to autosave when it changes. I am trying 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 field changes, I get the following error in jQuery:

  (c.value || "").replace is not a function 

This is like in jQuery-1.5.min.js. I also had the same error with jQuery-1.4.2.min.js. (I upgraded to 1.5 to make sure this helps.)

Any thoughts on where I'm wrong? Thank you very much.

Edit: Oh shit, when I receive my HTML message, I realized that I had a .live () call attached to the div container of the form input element and not the form input element itself. I have a separate problem, but I think I will post this when I find out what might cause it ...

+4
source share
1 answer

Uh, I figured it out ... a careless mistake. I had an input element in an HTML list element, and I had a .live () function call bound to the li id, not the input element id. Thanks for the help above guys.

+1
source

Source: https://habr.com/ru/post/1338602/


All Articles