Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

JS call within AJAX function

Featured Replies

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.

  • 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 by pippin

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 by andyl

  • 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

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.