Daniel Wilson
asked on
JQuery problem
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:
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.
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
Where am I messing this up? Thanks!
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...");
}
});
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...");
}
});
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>
Where am I messing this up? Thanks!
ASKER
You're right, there is a syntax error. That's what I get for doing Javascript past 3AM!
Suggestions on what I should be doing? I'll add the line you say as well to handle the optional parameter.
TypeError: divA.html is not a function
divA.html('<div align="center"><img src="images/ajax-loader.gif" /></div>');
Suggestions on what I should be doing? I'll add the line you say as well to handle the optional parameter.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
function getColAvg(sUser, dtData, unq){
becomes
function getColAvg(sUser, dtData, unq){
if(typeof(unq)==='undefine d') unq = "";
becomes
function getColAvg(sUser, dtData, unq){
if(typeof(unq)==='undefine
ASKER
Leakim971's solved it. Thanks to all who participated!
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 || '';