Jump to content

Passing JQuery AJAX data to variable outside AJAX function call...


RIRedinPA

Recommended Posts

Not sure if that made sense but here is what I am trying to do. I am dynamically building a display of database records in a grid (row, cols). Some of the cells use <select> form objects and I am using AJAX to help build them (the options in the select are stored in a db table). So my code looks like this (the return from the AJAX call is the complete <select><option value=1>...set up:

 

...
//write cell html
		   			if (d == 1) {
		   				userdata += "<p class=\"datacell date\">" + thisitemarray[1] + "</p>"; 
		   			} else if (d==2) {
		   			
		   				//make ajax call to get departments
		   				$.ajax({
   								type: "POST",
   								url: "lib/getDropDowns.php",
   								data: "thistable=departments&selecteditem=" + thisitemarray[1] + "&classnames=userdept userdatainput",
   								success: function(data){
     								userdata += "<p class=\"datacell department\">" + data + "</p>";
   								}
							});
		   			
		   			} else if (d == 3) { 
		   				userdata += "<p class=\"datacell bucket\"><input type=\"text\" value=\"" + thisitemarray[1] + "\" class=\"userbucket userdatainput\" dbid=\"" + dbid + "\"></p>";
		   			} else if (d == 4) {
		   				userdata += "<p class=\"datacell pubcode\"><input type=\"text\" value=\"" + thisitemarray[1] + "\" class=\"userpubcode userdatainput\" dbid=\"" + dbid + "\"></p>"; 
		   			} else if (d == 5) { 
		   				userdata += "<p class=\"datacell area\"><input type=\"text\" value=\"" + thisitemarray[1] + "\" class=\"userarea userdatainput\" dbid=\"" + dbid + "\"></p>";
		   			} else if (d == 6) { 
		   				userdata += "<p class=\"datacell hours\"><input type=\"text\" value=\"" + thisitemarray[1] + "\" class=\"userhours userdatainput\" dbid=\"" + dbid + "\"></p>";
		   			} else if (d == 7) { 
		   				userdata += "<p class=\"datacell description\"><textarea class=\"userdesc\" dbid=\"" + dbid + "\">" + thisitemarray[1] + "</textarea></p>";
		   			}//end d check 2

 

The problem is that this line of code:

 

success: function(data){
     								userdata += "<p class=\"datacell department\">" + data + "</p>";
   								}

 

does not show up on my page. I am assuming because userdata is being seen as a local variable within the function. How can I pull the data being passed from AJAX out into my script so I can use it?

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.