Solved

jquery get function does not work

Posted on 2012-03-16
10
342 Views
Last Modified: 2012-06-27
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);
0
Comment
Question by:erikTsomik
  • 4
  • 4
  • 2
10 Comments
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 37730523
1) does the URL work on its own?
2) why not $('#test' + ID).load("index.cfm");
0
 
LVL 19

Author Comment

by:erikTsomik
ID: 37730545
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');
0
 
LVL 9

Expert Comment

by:Shaun McNicholas
ID: 37730554
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)
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
LVL 19

Author Comment

by:erikTsomik
ID: 37730587
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>';
0
 
LVL 9

Accepted Solution

by:
Shaun McNicholas earned 400 total points
ID: 37730659
You also have this line:
tblOption+= temp;

Is temp a defined variable in the scripting somewhere else?

Also - do you have a javascript debugging tool you are using that will tell you when the script is failing. I think I see what you're trying to do but it seems like there are some missing elements somewhere....

for example what are you doing with these lines?

      $.get('index.cfm', function(data) {
        $('#test' + ID).html(data);
            });      

Are you trying to add the ajax return to the tblOption - because you aren't adding it in anywhere. The returned information will be contained within the variable data.

Assuming temp is defined somewhere and isn't causing the script to stop because of an undefined variable then the following should work I believe. Not knowing exactly the entire scope of this I am only assuming what you're trying to do.

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+=data;
                                    });      
	tblOption+='</td>';
	tblOption+='</tr>';

	$('#' + ID).append(tblOption);

Open in new window

0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 37730702
That was not what I meant
Just
    $("#test"+ID).load('index.cfm");
0
 
LVL 19

Author Comment

by:erikTsomik
ID: 37730704
hi maestropsm. It is still does not work
0
 
LVL 19

Author Closing Comment

by:erikTsomik
ID: 37730737
Great work. All I had to do is to place the rest of the code inside of the get
0
 
LVL 9

Expert Comment

by:Shaun McNicholas
ID: 37730750
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?
0
 
LVL 9

Expert Comment

by:Shaun McNicholas
ID: 37730755
Glad you figured it out.
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question