So this is the heart of my Chrome Extension [here], [jq
is jQuery.noConflict()
] the jq('.pam div .fbCurrentActionLink')
returns each "Poke" link on Facebook. It uses .each() to loop through each person [aka, each person's "poke" link], and on success, it replaces the text "Poke" with a bold & green "Poked" text.
function execute()
{
jq('.pam div .fbCurrentActionLink').each(function () {
anc=jq(this)
uid=anc.attr('ajaxify').match(/(\d+)/)[0]
//ajax
var post_form_id = jq('#post_form_id').val();
var fb_dtsg = jq('input[name=fb_dtsg]').val();
//use AJAX to submit poke, via their fb id
jq.ajax({
type: 'POST',
url: 'ajax/poke.php?__a=1',
data: 'uid=' + uid + '&pokeback=1&post_form_id=' + post_form_id + '&fb_dtsg=' + fb_dtsg + '&post_form_id_source=AsyncRequest',
beforeSend: function(xhr){
xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded; charset=UTF-8");
},
success: function(data, textStatus){
anc.html('<b style="color:green !important">Poked</b>');
}
});
//ajax
});
}
Now, the problem is, let's say there are 3 pokes to return. It will only execute the .html() on the last one. I can't figure out why.