Solved

jquery get function does not work

Posted on 2012-03-16
10
337 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
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 …
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 the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

746 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

12 Experts available now in Live!

Get 1:1 Help Now