Our team has been working on a javascript code that captures the URL of a selected image and stores it in a JavaScript variable called "src". The goal is to access this variable within a Rails view in order to obtain the ID of the selected image. We attempted to achieve this using Ajax, passing the URL to a variable created in the controller. However, we encountered issues with the Ajax call not functioning as expected, resulting in the controller variable always displaying a nil value. We explored two different methods for implementing Ajax:
Method 1:
$('#submit').click(function(){
$.ajax({
type: "POST",
url: "index",
cache: false,
data: "src="+src1,
success: function(){
alert("DATA SAVED");
}
});
Method 2:
<%= link_to_remote "submit" , :url=>{:controller=>'album',:action =>'index' ,:var=>'src1'}%>