Avatar of erikTsomik
erikTsomik
Flag for United States of America asked on

jquery get function does not work

I am writing a function which supposed to add a row to the html table. The first 2 columns get added just fine , but the third column need to use the content that derived from ajax call.

var tblOption = "";
                                    tblOption+='<tr>';
                                    tblOption+='<td>';
                                    tblOption+= temp;
                                    tblOption+='</td>';
                                    tblOption+='<td>';
                                    tblOption+='<img src="icon.gif" width="16" height="17"/>';
                                    tblOption+='</td>';
                                    tblOption+='<td>';
tblOption+= '<div id="test' + ID+ '"></div>';
                                    
                                    $.get('index.cfm, function(data) {
                                            
                                          $('#test' + ID).html(data);
                                    });      
tblOption+='</td>';
                                    tblOption+='</tr>';
                              
                                    
                                    
                                    $('#' + ID).append(tblOption);
JavaScriptScripting LanguagesAJAX

Avatar of undefined
Last Comment
Shaun McNicholas

8/22/2022 - Mon
Michel Plungjan

1) does the URL work on its own?
2) why not $('#test' + ID).load("index.cfm");
erikTsomik

ASKER
the link works on its own. Can i remove the div inside the td and append the content inside the td by saying $(this).load('index.cfm');
Shaun McNicholas

Looks like this like is missing a single quote causing the whole script to fail

replace this line:  $.get('index.cfm, function(data)
with this:  $.get('index.cfm', function(data)
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
erikTsomik

ASKER
I did I changed to this and it is still blowing up

tblOption+= '<div id="test">';
                                    tblOption+= $("#test").load('index.cfm?ID=' + ID);
                                    tblOption+='</div>';
ASKER CERTIFIED SOLUTION
Shaun McNicholas

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Michel Plungjan

That was not what I meant
Just
    $("#test"+ID).load('index.cfm");
erikTsomik

ASKER
hi maestropsm. It is still does not work
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
erikTsomik

ASKER
Great work. All I had to do is to place the rest of the code inside of the get
Shaun McNicholas

Again - is temp a variable or are you trying to insert the text temp into the tblOption variable?
If temp is not defined then your script is stopping because it doesn't know what you are wanting to do with the variable temp because it isn't defined.

If you are just trying to insert the text temp into the tblOption - then put it inside single quotes and everything should fire properly.

tblOption+= 'temp';

It might benefit you if you put the entire page up here so I can look at everything that's happening on the page and then I can see what you're trying to accomplish.

Also - I ask again - do you have some kind of script debugger running that can tell you where the script is stopping?
Shaun McNicholas

Glad you figured it out.
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy