// =================================================================================================
// As per set up in function RightMargin(), this responds to table links clicked in the right margin
function loadTables(event)
{
event.preventDefault() ;
var thislink=$(this).attr('href') ; // The URL of the link clicked
var destination='#' + $(this).data('target'); // The TARGET of the link clicked
var id_of_rowno='#' + $(this).data('link'); // Add'l info in the <input> element
var rowno = $(id_of_rowno).val() ; // Reads the value the the counter
var tablename= $(this).data('link'); // Use this value, ~ RtMgn_tablename
tablename = tablename.substring(6) ; // to extract the table whose data must be loaded
// getRandomIntInclusive(min, max) // Thinking (now) that I'll populate the form
var uniq_file_id = getRandomIntInclusive(1, 9999999999) ; // and have to save it uniquely before loading it
// This function will do the AJAX and return the page to load the the form populated
// after the SQL activity
// However when I run this, I'm getting the alert messages below as the very first thing,
// before it even call this function!!!
// ENTER PROMISES
var new_url = "" ;
if (tablename=="Modem")
{
// =================================================================
var maybe = new Promise(
// The resolver function is called with the ability to resolve or
// reject the promise
function(resolve, reject)
{
new_url = clicked_rightmarginTableLink(tablename, rowno, thislink, uniq_file_id) ;
resolve(new_url) ;
} // EO function for resolve or reject
) ; // EO Promise defined
maybe.then(
// Log and use the fulfillment value
function(new_url) {
alert("new_url="+new_url) ;
// Load the file
// $(destination).load("http://10.139.164.191/Cell_Modems/public_html/temp/modem_table_3671212420.html", function( response, status, xhr )
$(destination).load(new_url, function( response, status, xhr )
{
if ( status == "error" )
{
var msg = "Sorry but there was an error: ";
alert( msg + xhr.status + " " + xhr.statusText );
} // EO IF
}) ; // EO Callback for load AND load method itself
alert("Past .load") ;
})
.catch(
// Log the rejection reason
function(reason) {
console.log('Handle rejected promise ('+reason+') here.');
});
} // EO IF "Modem"
else
{
// Load the file (will be changed from this in the near future, once I get ajax deferred/promised/bleah!)
$(destination).load(thislink, function( response, status, xhr )
{
if ( status == "error" )
{
var msg = "Sorry but there was an error: ";
alert( msg + xhr.status + " " + xhr.statusText );
}
}) ;
} // EO else not "Modem"
} // EO function loadTables(event)
Experts Exchange (EE) has become my company's go-to resource to get answers. I've used EE to make decisions, solve problems and even save customers. OutagesIO has been a challenging project and... Keep reading >>
Our community of experts have been thoroughly vetted for their expertise and industry experience.