Solved

jquery get function does not work

Posted on 2012-03-16
10
352 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
Application Discovery Service in AWS

In the era of the cloud, customers migrating away from their existing on-premise infrastructure. This requires lots of planning, strategies, and effort to identify their existing resources and determine how best to migrate.  Datacenter migrations happen in four phases -

 
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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

The most up-to-date version of this article is on my Blog https://iconoun.com/blog/
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The viewer will learn how to dynamically set the form action using jQuery.
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…

617 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