@@ -31,7 +31,7 @@ define(function (require) {
3131 /**
3232 * Loads a JSON file from a file or a URL, and returns an Object or Array.
3333 * This method is asynchronous, meaning it may not finish before the next
34- * line in your sketch is executed, either use preload() to guarantee the
34+ * line in your sketch is executed. Either use preload() to guarantee the
3535 * file loads before setup() and draw() are called, or supply a callback
3636 * function that is executed when loadStrings() completes.
3737 *
@@ -46,14 +46,15 @@ define(function (require) {
4646 p5 . prototype . loadJSON = function ( path , callback ) {
4747 var ret = [ ] ;
4848 var t = path . indexOf ( 'http' ) === - 1 ? 'json' : 'jsonp' ;
49- reqwest ( { url : path , type : t , success : function ( resp ) {
50- for ( var k in resp ) {
51- ret [ k ] = resp [ k ] ;
52- }
53- if ( typeof callback !== 'undefined' ) {
54- callback ( ret ) ;
55- }
56- } } ) ;
49+ reqwest ( { url : path , type : t , crossOrigin : true } )
50+ . then ( function ( resp ) {
51+ for ( var k in resp ) {
52+ ret [ k ] = resp [ k ] ;
53+ }
54+ if ( typeof callback !== 'undefined' ) {
55+ callback ( ret ) ;
56+ }
57+ } ) ;
5758 return ret ;
5859 } ;
5960
@@ -68,7 +69,7 @@ define(function (require) {
6869 * URL for a file found on a network.
6970 *
7071 * This method is asynchronous, meaning it may not finish before the next
71- * line in your sketch is executed, either use preload() to guarantee the
72+ * line in your sketch is executed. Either use preload() to guarantee the
7273 * file loads before setup() and draw() are called, or supply a callback
7374 * function that is executed when loadStrings() completes.
7475 *
@@ -142,13 +143,18 @@ define(function (require) {
142143 *
143144 * <p> All files loaded and saved use UTF-8 encoding.</p>
144145 *
146+ * <p>This method is asynchronous, meaning it may not finish before the next
147+ * line in your sketch is executed. Either use preload() to guarantee the
148+ * file loads before setup() and draw() are called, or supply a callback
149+ * function that is executed when loadTable() completes.</p>
150+ *
145151 * @method loadTable
146152 * @param {String } filename name of the file or URL to load
147153 * @param {String|Strings } [options] "header" "csv" "tsv"
148- * @param {Function } [callback] function to be executed after loadXML ()
149- * completes, XML object is passed in as
154+ * @param {Function } [callback] function to be executed after loadTable ()
155+ * completes, Table object is passed in as
150156 * first argument
151- * @return {Object } XML object containing data
157+ * @return {Object } Table object containing data
152158 */
153159 p5 . prototype . loadTable = function ( path ) {
154160 var callback = null ;
@@ -238,7 +244,7 @@ define(function (require) {
238244 * URL for a file found on a network.
239245 *
240246 * This method is asynchronous, meaning it may not finish before the next
241- * line in your sketch is executed, either use preload() to guarantee the
247+ * line in your sketch is executed. Either use preload() to guarantee the
242248 * file loads before setup() and draw() are called, or supply a callback
243249 * function that is executed when loadXML() completes.
244250 *
@@ -254,13 +260,11 @@ define(function (require) {
254260 reqwest ( {
255261 url : path ,
256262 type : 'xml' ,
257- success : function ( resp ) {
258- ret [ 0 ] = resp ;
259- if ( typeof callback !== 'undefined' ) {
260- callback ( ret ) ;
261- }
262- }
263- } ) ;
263+ crossOrigin : true ,
264+ } )
265+ . then ( function ( resp ) {
266+ callback ( resp ) ;
267+ } ) ;
264268 return ret ;
265269 } ;
266270
0 commit comments