Reputation: 2847
In the view:
<div>
<%= radio_button_tag :profile_set, "Profile picture", true, onClick: "set_profile(#{picturething.id});" %>
</div>
<script type="text/javascript">
function set_profile(picid) {
alert("Hello.");
$.ajax({
type : 'POST',
url : '/update_profile_picture',
dataType : 'script',
data : { picid:picid, callsign:callsign, page_name:page_name }
});
alert("Goodbye.");
};
</script>
routes.rb:
post 'update_profile_picture', to: 'picturethings#update_profile', as: :update_profile_picture
I can see from the browser console that the ajax request is not firing, nothing happens. The "Hello" alert appears, so the code is executing at least that far, but falls over during the ajax bit. The "Goodbye" alert never appears.
Upvotes: 0
Views: 33
Reputation: 10769
As per my comment in the question, your ajax
looks fine... Just make sure you have defined page_name
and callsign
:
function set_profile(picid) {
alert("Hello.");
$.ajax({
type : 'POST',
url : '/update_profile_picture',
dataType : 'script',
data : { picid:picid, callsign:callsign, page_name:page_name }
});
alert("Goodbye.");
};
Upvotes: 1