Jseb Jseb - 6 months ago 16
Javascript Question

Ruby on Rails with jquery load and sending data

I am wondering how I can send data. I have the following code

$( "#dialog" ).load('/events/relates ' + '#eventconfirm', { data: 'Hello World' }).dialog('open');


But it doesn't work. What I want is to load
event/relates
and only get the selection
#eventconfirm
, which works, but I would like to add data so the controller can read the
params[:data]
and act upon it.

Answer

no need to append the url and try calling the plugin in the .load callback like

$("#dialog").dialog();//first initailize the plugin
//then load the content 
$( "#dialog" ).load('/events/relates#eventconfirm', { data: 'Hello World' },function(data){
 $(this).dialog('open');
});

DEMO