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.

Recommended Answers

All 5 Replies

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);
			
		});
	});
});

Thanks for the reply, worked great (:

+1 rep for your help

ello (:

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?

$(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);
	});
	
});

Perfect! Thanks, worked a treat (:

+1

ello (:

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.