Last active
April 27, 2016 02:04
-
-
Save msmfsd/2addc92ebc238e826d4940e4861c3ac9 to your computer and use it in GitHub Desktop.
ES6 class to load php/html/* content into a div via jQuery
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// USAGE: | |
// import LoadContent from './load-content.js'; | |
// LoadContent.Load($('#myDiv'), 'http://myContent.php', { id:1, data:mydata }, callbackFunction); | |
// DEPENDANCIES: jQuery, Babel ES6 | |
"use strict"; | |
/* | |
* CLASS: LoadContent | |
* DESC: Load php/html/* content into a div via jQuery | |
*/ | |
export class LoadContent { | |
/************************************************************* VARS */ | |
static JQuery = typeof jQuery != 'undefined'; | |
/************************************************************* METHODS */ | |
constructor() { } | |
/* | |
* method: Load | |
* type: static | |
* @ _div: jQuery element | |
* @ _url: String | |
* @ _data: Object : default: {} | |
* @ _callback: Function | |
*/ | |
static Load(_div, _url, _data = {}, _callback) { | |
// ensure jQuery Object is loaded | |
if(!LoadContent.JQuery) return false; | |
// jQuery load | |
_div.load(_url, _data, function(responseText, textStatus, XMLHttpRequest) { | |
// server response | |
if(textStatus === "success") _callback(textStatus); | |
else { | |
_div.html('<p>' + textStatus + '</p>'); | |
_callback(textStatus); | |
} | |
}); | |
} | |
} // end class |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment