[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

JQuery problem

Posted on 2014-12-05
5
Medium Priority
?
225 Views
Last Modified: 2014-12-05
I changed a small script last night that is supposed to perform an asynchronous call and fill in the div via AJAX.

I changed the following code:
function getColAvg(sUser, dtData){	
$('#DivColAverages').html('<div align="center"><img src="images/ajax-loader.gif" /></div>');
jQuery.ajax({
	type: "GET",
	url: "options.php?option=ColAvg&dataDate=" + dtData + "&User=" +sUser,
	dataType: "html",
	success: function(response){
		$('#DivColAverages').html('');
		$('#DivColAverages').html(response);
	},
	error: function(){
		//alert("Error occured during Ajax request...");
	}
});		

Open in new window



to permit the addition of a unique suffix to the div ID so that I can have more than 1 of these on the page.
function getColAvg(sUser, dtData, unq=''){	
var divA = document.getElementById('DivColAverages' + unq);
divA.html('<div align="center"><img src="images/ajax-loader.gif" /></div>');
jQuery.ajax({
	type: "GET",
	url: "options.php?option=ColAvg&dataDate=" + dtData + "&User=" +sUser,
	dataType: "html",
	success: function(response){
		var divA = document.getElementById('DivColAverages' + unq);
		divA.html('');
		divA.html(response);
	},
	error: function(){
		//alert("Error occured during Ajax request...");
	}
});		

Open in new window


And ... it no longer does the call, as far as I can tell. Firebug permits me to see that line 3 executes, but after execution the div code remains
 
<div id="DivColAverages" class="f_r_f_p_body">
<script>
getColAvg('SCAM','11/28/2014');
</script>
</div>

Open in new window


Where am I messing this up?  Thanks!
0
Comment
Question by:Daniel Wilson
[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
5 Comments
 
LVL 24

Expert Comment

by:mankowitz
ID: 40483334
Did you check the console? Are you sure that you aren't getting a syntax error on the line
  function getColAvg(sUser, dtData, unq=''){

that isn't standard javascript. You'd have to do something like this:
  function getColAvg(sUser, dtData, unq){
    unq = unq || '';
0
 
LVL 32

Author Comment

by:Daniel Wilson
ID: 40483354
You're right, there is a syntax error.  That's what I get for doing Javascript past 3AM!
TypeError: divA.html is not a function
	

divA.html('<div align="center"><img src="images/ajax-loader.gif" /></div>');

Open in new window


Suggestions on what I should be doing?  I'll add the line you say as well to handle the optional parameter.
0
 
LVL 82

Accepted Solution

by:
leakim971 earned 2000 total points
ID: 40483367
try this :
<!DOCTYPE html>
<html>
<head>
	<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
	<script>
		jQuery(function($) {
			function getColAvg(sUser, dtData, unq='') {	
				$('#DivColAverages' + unq).html('<div align="center"><img src="images/ajax-loader.gif" /></div>');
				jQuery.ajax({
					type: "GET",
					url: "options.php?option=ColAvg&dataDate=" + dtData + "&User=" +sUser,
					dataType: "html",
					success: function(response){
						$('#DivColAverages' + unq).html(response);
					},
					error: function(){
						alert("Error occured during Ajax request...");
					}
				});		
			}
			getColAvg('SCAM','11/28/2014');
		});
		
	</script>
</head>
<body>
	<div id="DivColAverages" class="f_r_f_p_body"></div>
</body>
</html>

Open in new window

0
 
LVL 58

Expert Comment

by:Gary
ID: 40483435
function getColAvg(sUser, dtData, unq){

becomes

function getColAvg(sUser, dtData, unq){
if(typeof(unq)==='undefined') unq = "";
0
 
LVL 32

Author Closing Comment

by:Daniel Wilson
ID: 40483549
Leakim971's solved it.  Thanks to all who participated!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction JSON is an acronym for JavaScript Object Notation.  It is a text-string data transport mechanism, capable of representing simple or complex data structures in a consistent and easy-to-read manner.  Similar in concept to XML, but more e…
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
The viewer will learn how to dynamically set the form action using jQuery.
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…
Suggested Courses

649 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