Solved

jquery get function does not work

Posted on 2012-03-16
10
349 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
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

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

Suggested Solutions

I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
This article discusses how to create an extensible mechanism for linked drop downs.
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
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…

710 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