Solved

jquery get function does not work

Posted on 2012-03-16
10
338 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
 
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
DevOps Toolchain Recommendations

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

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

911 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now