January 26, 201115 yr Hey guys, been searching for this but it's all a bit hazy and very specific to what other people were after. Just wondered if someone knew how to run a JavaScript function within an AJAX function? I'll post both my AJAX and JS and if anyone could just show me how to do this it'd be great. It's Just a little test document [hence, www.google.com] but can't seem to fire the JS when the AJAX is called. AJAX $(document).ready(function(){ $('#xavisys-logo').live('click', function(e) { var r1=''; var r2=''; e.preventDefault(); $.get("char_con.php?", {act: 'char_con'}, function(data){ r1=data; }); $.getJSON("generator.php?", {act: 'char_con', bc: '1'}, function(data){ r2=data; $(".quote").html( r1 + r2 ); }); }); }); JavaScript function myinfo() { window.open ( "http://www.google.com/" ) } Any help appreciated Pippin.
January 26, 201115 yr Author What do you need to happen? A popup window on click? Yeah, the onclick I had before no longer works now I have the AJAX involved, so I was wondering how to maybe do it in the function? Maybe this was the wrong way to go about doing it, I'm not too sure. But yes, just a simple popup window on click is what I'm after A popup window aswell as the origional function I may add. Edited January 26, 201115 yr by pippin
January 26, 201115 yr A bit tongue-in-cheek, but this should work: $(document).ready(function(){ $('#xavisys-logo').live('click', function(e) { var r1=''; var r2=''; e.preventDefault(); $.get("char_con.php?", {act: 'char_con'}, function(data){ r1=data; }); $.getJSON("generator.php?", {act: 'char_con', bc: '1'}, function(data){ r2=data; $(".quote").html( r1 + r2 ); window.open ( "http://www.google.com/" ); }); }); }); No need for that function you've written for a one liner. Edited January 26, 201115 yr by andyl
January 27, 201115 yr Author A bit tongue-in-cheek, but this should work: $(document).ready(function(){ $('#xavisys-logo').live('click', function(e) { var r1=''; var r2=''; e.preventDefault(); $.get("char_con.php?", {act: 'char_con'}, function(data){ r1=data; }); $.getJSON("generator.php?", {act: 'char_con', bc: '1'}, function(data){ r2=data; $(".quote").html( r1 + r2 ); window.open ( "http://www.google.com/" ); }); }); }); No need for that function you've written for a one liner. Cheers Andyl, worked as allways. didn't know you could just include them in the code like that, cheers. But the function was just because I used to have it as an onclick, only reason Pippin.
Create an account or sign in to comment