javascript - Call same ajax from different element clicks with different data -


i'm trying call same ajax function different elements different data.

for eg: i've these 2 links

<a href="#!" id="link1" data-source="google">google</a> <a href="#!" id="link2" data-source="facebook">facebook</a> 

and ajax call like:

$("#link1).click(function() {    $.post(     '/myphpscript/',          {           data:$("#link1).attr('data-source')         }, // data want send script         function (data) {           } }); 

i know can call same ajax different elements this:

$('#link1, #link2').click(some_function); 

but how select data based on clicking element?

use instance of this, also, give links common class , use simple selector:

$(".ajaxlinks").click(function() {     $.post('/myphpscript/', { data:$(this).attr('data-source') }, function (data) {      }); }); 

Comments

Popular posts from this blog

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

java - Could not locate OpenAL library -

sorting - opencl Bitonic sort with 64 bits keys -