0

hey guys could anyone quickly show me how I'd go about combining these:

$(document).ready(function(){

	$("#generate-quote").click(function(e){

		e.preventDefault();

		$.getJSON("generator.php?", {act: 'char_con', bc: '1'}, function(data){

			$(".quote").html(data);
		});
                                        

	});
                                
                                
});
$(document).ready(function(){

	$("#env").click(function(e) {

		e.preventDefault();

		$.get("char_con.php?", {act: 'char_con'}, function(data{							  
			$(".q").html(data);
			
		});
	});
});

Right now they obviously do different things, but what I'm after is:

$(document).ready(function(){

	$("#env").click(function(e) {

		e.preventDefault();

                        // do both

			$(".q").html(data);
			
		});
	});
});

I know how to make it call multiple functions, but I'm just a bit confused as ones using .getJSON so nothing I've tried has worked as of yet,

anyone know how this would be done?

Thanks for any help.

Edited by ello: n/a

2
Contributors
5
Replies
6
Views
6 Years
Discussion Span
Last Post by ello
0

at the end of line 7 of your second code block you have: function(data{ It is missing a closing parenthesis. Try:

$(document).ready(function(){

	$("#env").click(function(e) {

		e.preventDefault();

                        // do both
                        $.getJSON("generator.php?", {act: 'char_con', bc: '1'}, function(data){

			$(".quote").html(data);


		});

                        $.get("char_con.php?", {act: 'char_con'}, function(data){							  
        			$(".q").html(data);
         		});

			$(".q").html(data);
			
		});
	});
});
0

Thanks for the reply, worked great (:

+1 rep for your help

ello (:

Edited by ello: n/a

0

On second thought, a small problem with the code.

here's the code that works:

$(document).ready(function(){
 
	$("#env").click(function(e) {
 
			e.preventDefault();
			 
			$.get("char_con.php?", {act: 'char_con'}, function(data){							  
			$(".q").html(data);

			});
			
			$.getJSON("generator.php?", {act: 'char_con', bc: '1'}, function(data){
	 
			$(".q").html(data);
 
		});
			
	});
	
});

This runs the first, then second in quick succession.

For example if you were to have these call two separate functions in separate files which both echoed an image, like so:

file 1:

echo'image.gif'

file 2:

echo'image2.gif

it would display the first image, then the first image would disappear, and the second image would be displayed.

Is there a way to KEEP the first image displayed, then the second one over the top?

Edited by ello: n/a

0
$(document).ready(function(){
 
	$("#env").click(function(e) {
 
			e.preventDefault();

			var r1='';
			var r2='';
			$.get("char_con.php?", {act: 'char_con'}, function(data){
				//save the result of the first call onto r2
				r1=data;
			});
			
			$.getJSON("generator.php?", {act: 'char_con', bc: '1'}, function(data){
				//save the result of the second call onto r2
	 			r2=data;
			});

			//take both results and save them onto .q
			$(".q").html( r1 + r2);
	});
	
});
0

Perfect! Thanks, worked a treat (:

+1

ello (:

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.