lundi 16 février 2015

"NetworkError: 404 Not Found" - $.post() with jquery


Here is js code in our Rais 3.2 app responding to change of fields whose ids start with 'order_order_items_attributes':



$(function (){
$(document).on('change', "[id^='order_order_items_attributes'][id$='_name']", function (){
$.post(window.location, $('form').serialize(), null, "script");
return false;
});
});


The $.post() causes the error:



"NetworkError: 404 Not Found - http://localhost:3000/po/orders/new?parent_record_id=4&parent_resource=ext_construction_projectx%2Fprojects&project_id=4%22"


Here is the window.location: enter image description here


If we replace $.post() with $.get(), then the code works fine and fires up the ajax response on the server:



$.get(window.location, $('form').serialize(), null, "script"); #works!


But we have to use $.post() because of the large amount of data being posted to the server. The jquery document shows that $.get() and $.post() have exactly the same format. What we missed here with $.post()? Thanks.





Aucun commentaire:

Enregistrer un commentaire