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?

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.