Ralph
asked on
My AJAX callbacks aren't being found
I have three Ajax's total, two invocations in one function and the third in another, running every 10 seconds.
The callbacks are named: callback_ImportPostProcess ing#, where # is { 1, 2, 3 }
Chrome's inspector says: Uncaught ReferenceError: callback_ImportPostProcess ingX is not defined
What do you suppose is up? This is something new. See also the attachment.
The switch and correct case are being visited in likes 929-934.
function ImportPostProcessing() is the document's ready function.
Thanks thanks thanks!
To-ExpertsExchange.PNG
The callbacks are named: callback_ImportPostProcess
Chrome's inspector says: Uncaught ReferenceError: callback_ImportPostProcess
What do you suppose is up? This is something new. See also the attachment.
The switch and correct case are being visited in likes 929-934.
function ImportPostProcessing() is the document's ready function.
function ImportPostProcessing()
{
var posting_period ;
var $object = $("#center_body") ;
var holder =$object.data()
var type_of_invoice = holder.type_of_invoice ; // This info stashed here in StartupScripts.js, function loadLeftMarginListLink(event)
alert("type_of_invoice="+type_of_invoice) ;
type_of_invoice = "Charge" ; // Until I can get variables working.
var php_params="job=ImportPostProcessing&task=Initial&type_of_invoice="+type_of_invoice ;
// -----------------------------------------------------------------------------------------------
// Do Ajax call to PHP to MySQL to get date_of_import=(timestamp of when it started), and
// what=(something like Mar "2015 Charges for current period")
doAjax_ImportPostProcessing(php_params, callback_ImportPostProcessing1) ;
function callback_ImportPostProcessing1(jqXHR, data)
{
console.log("Inside callback_ImportPostProcessing1, jqXHR.status="+jqXHR.status) ;
alert ("In callback 1") ;
// -----------------------------------------------------------------------------------------------
// Use results
var nrows = JSON.parse(data).nrows ;
if (nrows == 0)
{
return ;
}
var answer = JSON.parse(data).values ;
var when_started = answer[1].date_of_import ;
var identifier = answer[1].what ;
posting_period=identifier.substr(0,8) ; // js stupidly here wants 1 more than it'll take. (start, end+1)
// This will be something like "Apr 2016"
// ===============================================================================================
// Now that the page is up (the link in the left margin Workflow page did it w/o interruption)
// we can use the start time to get the interval since kickoff
// Javascript
var year = when_started.substring(0,4) ; // 0 1 2 3
var mon = when_started.substring(5,7) ; // 5 6
var day = when_started.substring(8,10) ; // 8 9
var hour = when_started.substring(11,13) ; // 11 12
var min = when_started.substring(14,16) ; // 14 15
var sec = when_started.substring(17,19) ; // 17 18
// javascript makes me do this
mon = mon -1 ;
var whenstartedPHP = new DATE(year, mon, day, hour, min, sec) ;
var now = new DATE() ;
var elapsedTime = getElapsed_HMS(whenstartedPHP, now) ;
// jQuery, put that value there now
$("#elapsed_time").val(elapsedTime) ;
// Save this for access so I can keep showing the elapsed time
$.data("import_started_at",whenstartedPHP) ;
// =============================================================================================
// Start looking until user leaves this page or until we find we've GOT COMPLETION!
var myVar = setInterval(cyclicallyCheckingForImportCompletion(type_of_invoice, posting_period), 1000);
// Keep this value so I can stop the cycling from a different context if I have to
// Stop via clearInterval(myVar) ;
$.data("post_processing_timer_id",myVar) ;
} // End of callback_ImportPostProcessing1()
// ***********************************************************************************************
// _______________________________________________________________________________________________
// This Ajax will retrieve the results of two CALLs to SQL Procedure InvoicePostProcessingCheck
php_params="job=ImportPostProcessing&task=Get2Views&posting_period="+posting_period+"&type_of_invoice="+type_of_invoice ;
// -----------------------------------------------------------------------------------------------
// Do Ajax call
doAjax_ImportPostProcessing(php_params, callback_ImportPostProcessing2) ;
function callback_ImportPostProcessing2(jqXHR, data)
{
console.log("Inside callback_ImportPostProcessing2, jqXHR.status="+jqXHR.status) ;
alert ("In callback 2") ;
// -----------------------------------------------------------------------------------------------
// Use Ajax results to populate
var nrows = JSON.parse(data).nrows ;
if (nrows == 0)
{
return ;
}
var answer = JSON.parse(data).values ;
$("#import_count").val(answer[1].import_count) ;
$("#raw_data_row_count").val(answer[1].raw_data_row_count) ;
} // End of callback_Import_postProcessing2()
} // End of ImportPostProcessingCheck()
// =================================================================================================
// =================================================================================================
function cyclicallyCheckingForImportCompletion(type_of_invoice, posting_period)
{
// We'llcome back here every second to show elapsed time.
// Every 10 seconds do a query (via that PROC) to get the 3rd view option
var whenstartedPHP = $.data("import_started_at") ;
var now = new DATE() ;
var elapsedTime = getElapsed_HMS(whenstartedPHP, now) ;
var timer_id ;
// Set elapsed time into form
$("#elapsed_time").val(elapsedTime) ;
// -----------------------------------------------------------------------------------------------
// Every 10 seconds do another Ajax to PHP to MySQL CALL to InvoicePostProcessingCheck
if (parseInt(elapsedTime.substring(6,8),10) % 10 == 0 ) // Every 10 seconds do another check
{
var php_params="job=ImportPostProcessing&task=CyclicalFor3rdView&type_of_invoice="+type_of_invoice ;
php_params=php_params+"&posting_period="+posting_period ;
doAjax_ImportPostProcessing(php_params, callback_CyclicalImportPostProcessing) ;
function callback_ImportPostProcessing3(jqXHR, data)
{
console.log("Inside callback_ImportPostProcessingCheck, jqXHR.status="+jqXHR.status) ;
var answer = JSON.parse(data).values ;
$("#identifier").val(answer[1].identifier) ;
$("#when_started").val(answer[1].when_started) ;
$("#rows_processed").val(answer[1].rows_processed) ;
$("#rows_in_source").val(answer[1].rows_in_source) ;
$("#status").val(answer[1].status) ;
} // EO callback for Ajax
} // EO Time to refresh
if ( $("#status").val().indexOf('Invoice Import completed successfully') != 0 ) // We're done!
{
timer_id = window.data("post_processing_timer_id") ;
clearInterval(timer_id) ;
window.removeData("import_started_at") ;
window.removeData("post_processing_timer_id") ;
$("#status").css('background-color: lightpink') ;
} // We've stopped cycling and highlighted the completion status
}
// =================================================================================================
// =================================================================================================
function doAjax_ImportPostProcessing(php_params, callbackFunction)
{
$('#debug').html(php_params) ;
// Would like to use DIV to keep user informed while waiting
$('#AjaxMessage').html(ajax_outstanding+" Active Searches") ;
if (ajax_outstanding <= 0) { $("#progress_bar").hide() ; }
var pthing = php_params.indexOf("task=") ;
var task = php_params.substr(pthing+5) ;
pthing = task.indexOf("&") ;
task=task.substr(0,pthing) ;
alert("task at start="+task) ;
// -----------------------------------------------------------------------------------------------
// Do the magic
var jqXHR = $.ajax({
url: 'http://somepath/cmdb/PHP/do_WorkFlow_query.php' ,
method: "GET" ,
cache: false ,
data: php_params ,
beforeSend: beforeSend_ImportPostProcessing ,
fail: fail_ImportPostProcessing ,
success: success_ImportPostProcessing
}) ;
// -----------------------------------------------------------------------------------------------
function beforeSend_ImportPostProcessing(jqXHR, settings)
{ ajax_outstanding++;
$('#AjaxMessage').html(ajax_outstanding+" Active Searches") ;
$('#AjaxResults').html("") ;
$("#progress_bar").show() ;
return ;
} ;
// -----------------------------------------------------------------------------------------------
function fail_ImportPostProcessing(jqXHR, errDesc, exception)
{
ajax_outstanding-- ;
$('#AjaxMessage').html(ajax_outstanding+" Active Searches") ;
if (ajax_outstanding <= 0) { $("#progress_bar").hide() ; }
alert(errDesc+" while task="+task+'.');
} ;
// -----------------------------------------------------------------------------------------------
function success_ImportPostProcessing(data, status, jqXHR)
{
ajax_outstanding-- ;
$('#AjaxMessage').html(ajax_outstanding+" Active Searches") ;
if (ajax_outstanding <= 0) { $("#progress_bar").hide() ; }
if (status !== "success")
{
alert('Search results not found while task='+task+'.') ;
$('#AjaxResults').html("") ;
}
else
{
var nrows = JSON.parse(data).nrows ;
if (nrows === 0)
{
$('#AjaxResults').html("Import post processing task '"+task+"' yielded 0 rows.") ;
$('#AjaxResults').addClass('flashBkgrndRed');
setTimeout(function() { $('#AjaxResults').removeClass('flashBkgrndRed'); }, 200);
}
else
{
var answer = JSON.parse(data).values ;
$('#AjaxResults').html("Import post processing task '"+task+"' yielded "+nrows+" rows.") ;
$('#AjaxResults').addClass('flashBrdrGreen');
setTimeout(function() { $('#AjaxResults').removeClass('flashBrdrGreen'); }, 800);
alert("task at success="+task) ;
if (typeof callbackFunction === 'function')
{
switch (task)
{
case "Initial": callback_ImportPostProcessing1(jqXHR, jsonData) ; break ;
case "Get2Views": callback_ImportPostProcessing2(jqXHR, jsonData) ; break ;
case "CyclicalFor3rdView": callback_ImportPostProcessing3(jqXHR, jsonData) ; break ;
}
}
} // EO nrows != 0
} // EO success
}; // EO function success_4ModemSwap_On((data, status, jqXHR)
// -----------------------------------------------------------------------------------------------
function stop_ImportPostProcessing( response, status)
{
ajax_outstanding = 0 ;
$('#AjaxMessage').html(ajax_outstanding+" Active Searches") ;
if (ajax_outstanding <= 0) { $("#progress_bar").hide() ; }
}
} // EO function clicked_search_ImportPostProcessing()
Thanks thanks thanks!
To-ExpertsExchange.PNG
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
See prior comment when I THOUGHT I was closing this.
Thanks again Ryan,
Ralph
Thanks again Ryan,
Ralph
ASKER
A case of a major brain fart I'm afraid, I just could not see it.
All (JS wise) is good now.
Thanks again.