Skip to content

Instantly share code, notes, and snippets.

@msmfsd
Last active April 27, 2016 02:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save msmfsd/2addc92ebc238e826d4940e4861c3ac9 to your computer and use it in GitHub Desktop.
Save msmfsd/2addc92ebc238e826d4940e4861c3ac9 to your computer and use it in GitHub Desktop.
ES6 class to load php/html/* content into a div via jQuery
// 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