/ Published in: jQuery

URL: http://www.mobiledesign.com
Json data handling object. Provides two static methods for handling json data retrieval in conjunction with the jQuery ajax and json parser.
Expand |
Embed | Plain Text
/////////////////////////// //JSONObj.js //JSON data handler. /////////////////////////// //JSON data handling object. JSONObj = { getdataurl: function(url, type, data) { var jqxhr = null; var type_string = (!type) ? 'GET' : type; var dat = (data === null) ? null : data; //AJAX defaults. $.ajaxSetup({ url: url, global: true, type: type_string, data: dat, dataType: 'json', cache: false }); //Return data. jqxhr = $.ajax(); return jqxhr; }, getdatavar: function(variable) { //Parse JSON data from variable. var json = jQuery.parseJSON(variable); //Return data. return json; } }; /////////////////////////// /////////////////////////// //Example: /////////////////////////// var jsondata = new JSONObj.getdataurl('http://your/data/url'); $.when(jsondata).then(function(json){ doSomethingWithIt(json); }) .fail(function(){ console.log('JSON Data not received, halt...'); }); ///////////////////////////
Comments

You need to login to post a comment.
the 8 best vintage puzzles 1000 piece the8best