Solved

JQuery problem

Posted on 2014-12-05
5
223 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 500 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

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

Question has a verified solution.

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

In this article you'll learn how to use Ajax calls within your CodeIgniter application. To explain this, I'll illustrate how to implement a simple contact form to allow visitors to send you an email through your web site.
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)
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…

695 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