1 Replies - 7982 Views - Last Post: 01 July 2009 - 09:20 AM

#1 hrvoje89  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 63
  • Joined: 05-February 09

jQuery - multiple $.ajax calls

Post icon  Posted 28 June 2009 - 11:12 AM

Hello all,

I have this code:

				var partnum = $(this).attr('href');

				$.ajax({
				   type: "POST",
				   url: "kosarica.php",
 				   data: "do=makni&partnum="+partnum+""
				});
				
				$.ajax({
				   type: "POST",
				   url: "kosarica.php",
 				   data: "do=get_gotovina&partnum="+partnum+"",
				   success: function(msg){
				   alert( "Data Saved: " + msg );
				   }

				});	


the first $.ajax works fine, but the second doesn't get the partnum variable...when i comment out the first $.ajax.. the second one works normaly..
so i guess i should rename each $.ajax so they are not called the same... or what?

how can i fix it?

Ty!

Is This A Good Question/Topic? 0
  • +

Replies To: jQuery - multiple $.ajax calls

#2 dimjaxor  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 40
  • Joined: 10-September 08

Re: jQuery - multiple $.ajax calls

Posted 01 July 2009 - 09:20 AM

View Posthrvoje89, on 28 Jun, 2009 - 10:12 AM, said:

Hello all,

I have this code:

				var partnum = $(this).attr('href');

				$.ajax({
				   type: "POST",
				   url: "kosarica.php",
 				   data: "do=makni&partnum="+partnum+""
				});
				
				$.ajax({
				   type: "POST",
				   url: "kosarica.php",
 				   data: "do=get_gotovina&partnum="+partnum+"",
				   success: function(msg){
									 alert( "Data Saved: " + msg );
								   }

				});	


the first $.ajax works fine, but the second doesn't get the partnum variable...when i comment out the first $.ajax.. the second one works normaly..
so i guess i should rename each $.ajax so they are not called the same... or what?

how can i fix it?

Ty!

I think you could try using the .ajaxStop method, ajaxStop executes a function whenever all AJAX requests have ended.

so maybe
			var partnum = $(this).attr('href');

				$.ajax({
				   type: "POST",
				   url: "kosarica.php",
 				   data: "do=makni&partnum="+partnum+""
				});
				
				$.ajaxStop(function(){
					$.ajax({
					   type: "POST",
					   url: "kosarica.php",
 					   data: "do=get_gotovina&partnum="+partnum+"",
					   success: function(msg){
							alert( "Data Saved: " + msg );
										   }
										 });
								 });



I haven't tried making multiple ajax calls, I kind of had it in the back of my head that it would be simple, until I started thinking about how to do it.
I'm guessing it would run that ajax call then the ajaxStop would wait for the call to stop and execute the next ajax call.

Let me know if that works out.

This post has been edited by dimjaxor: 01 July 2009 - 09:23 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1