javascript - How to call ajax by clicking d3.js graph -


i want call ajax function send data graph (d3.js forced layout graph) controller action in rails.

my graph created json (from classic miserables example). want allow user click on node , trigger ajax 'get' call action in rails.

the controller called users , action show want send name of node show action

so far have:

 var node = svg.selectall(".node")       .data(graph.nodes)       .enter().append("circle")       .attr("class", "node")       .attr("r", function(d) { return d.group * 3; })       .style("fill", function(d) { return color(d.group); })       .call(force.drag)       .on("click",  getprofile(d.name));})        .on('dblclick', connectednodes);   function getprofile(){ $.ajax({ type: "get", url: "/users/show" , }) }; 

obviously doesn't work. i'm not sure how pass name of node ajax.

i don't have access variables, ran stripped down version , seems work. changed line:

.on("click",  getprofile(d.name));}) 

to

.on("click",  function(d) { getprofile(d.name); }) 

and don't know in ajax call planning on plugging name variable in, this:

function getprofile(name){     console.log(name); }; 

will console.log d.name node. can use name var plug in wherever need in ajax call. hope helps.


Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -