greasemonkey - Links from ajax request are not requested via ajax -


i have userscript fires ajax call via gm_xmlhttprequest load simple page text , links div named "debug". works well. want, every link in requested document requested via gm_xmlhttprequest. don't know why function not working

    $('.ajax, .ajaxn').click(function(event) {  event.preventdefault();  var href = $(this).attr('href'); gm_xmlhttprequest({                 method: "get",                 url: href,                 headers: {                     "content-type": "application/x-www-form-urlencoded"                     },                         onload: function(response) {                                 $('#debug').html('');                                 $('#debug').append(response.responsetext).fadein(5000);                                         }             }); }); 

the links inside response have class ajaxn, , firebug dom/html panel shows response inserted #debug

any hints?

the question not clear, assuming want click handler fire, if link clicked in #debug content (versus auto-loading links or ???)...

then don't use .click() method. use jquery's .on() method fires on current, and future, nodes match selector.

the code becomes like:

$(document).on ("click", ".ajax, .ajaxn", function (event) {     event.preventdefault ();     var href = $(this).attr('href');      gm_xmlhttprequest ( {         method:     "get",         url:        href,         headers:    {             "content-type": "application/x-www-form-urlencoded"         },         onload:     function (response) {             $('#debug').empty ();             $('#debug').append (response.responsetext).fadein (5000);         }     } ); } ); 


also, don't use $('#debug').html('');   use $('#debug').empty(); instead. smidge faster , code little more self-documenting.


Comments

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -

Python Pig Latin Translator -