dist/evrythng.js
function jsonp(options, successCallback, errorCallback) {
    /*jshint camelcase:false */

    options = options || {};

    // Define unique callback name.
    var uniqueName = 'callback_json' + (++counter);

    // Send all data (including method, api key and data) via GET
    // request params.
    var params = options.params || {};
    params.callback = uniqueName;
    params.access_token = options.authorization;
    params.method = options.method || 'get';
    params.data = JSON.stringify(options.data);
    options.params = params;

    options.apiUrl = options.apiUrl && options.apiUrl.replace('//api', '//js-api');

    // Evrythng REST API default endpoint does not provide JSON-P
    // support, which '//js-api.evrythng.com' does.
    var url = Utils.buildUrl(options);

    // Return a promise and resolve/reject it in the callback function.
    return new Promise(function(resolve, reject) {

      // Attach callback as a global method. Evrythng's REST API error
      // responses always have a status and array of errors.
      window[uniqueName] = function(response){

        if (response.errors && response.status) {

          var errorData = _buildError(url, response.status, params.method, response);
          Logger.error(errorData);

          if(errorCallback) {
            Logger.warnCallbackDeprecation();
            errorCallback(errorData);
          }
          reject(errorData);

        }else {

          if(successCallback) {
            Logger.warnCallbackDeprecation();
            successCallback(response);
          }

          try {
            response = JSON.parse(response);
          } catch(e){}

          resolve(response);
        }

        // Remove callback from window.
        try {
          delete window[uniqueName];
        } catch (e) {}
        window[uniqueName] = null;
      };

      _load(url, reject);

    });
  }
function jsonp(options, successCallback, errorCallback) {
    /*jshint camelcase:false */

    options = options || {};

    // Define unique callback name.
    var uniqueName = 'callback_json' + (++counter);

    // Send all data (including method, api key and data) via GET
    // request params.
    var params = options.params || {};
    params.callback = uniqueName;
    params.access_token = options.authorization;
    params.method = options.method || 'get';
    params.data = JSON.stringify(options.data);
    options.params = params;

    options.apiUrl = options.apiUrl && options.apiUrl.replace('//api', '//js-api');

    // Evrythng REST API default endpoint does not provide JSON-P
    // support, which '//js-api.evrythng.com' does.
    var url = Utils.buildUrl(options);

    // Return a promise and resolve/reject it in the callback function.
    return new Promise(function(resolve, reject) {

      // Attach callback as a global method. Evrythng's REST API error
      // responses always have a status and array of errors.
      window[uniqueName] = function(response){

        if (response.errors && response.status) {

          var errorData = _buildError(url, response.status, params.method, response);
          Logger.error(errorData);

          if(errorCallback) {
            Logger.warnCallbackDeprecation();
            errorCallback(errorData);
          }
          reject(errorData);

        }else {

          if(successCallback) {
            Logger.warnCallbackDeprecation();
            successCallback(response);
          }

          try {
            response = JSON.parse(response);
          } catch(e){}

          resolve(response);
        }

        // Remove callback from window.
        try {
          delete window[uniqueName];
        } catch (e) {}
        window[uniqueName] = null;
      };

      _load(url, reject);

    });
  }
function jsonp ( options , successCallback , errorCallback ) { /*jshint camelcase:false */ options = options || { } ; // Define unique callback name. var uniqueName = 'callback_json' + ( ++ counter ) ; // Send all data (including method, api key and data) via GET // request params. var params = options . params || { } ; params . callback = uniqueName ; params . access_token = options . authorization ; params . method = options . method || 'get' ; params . data = JSON . stringify ( options . data ) ; options . params = params ; options . apiUrl = options . apiUrl && options . apiUrl . replace ( '//api' , '//js-api' ) ; // Evrythng REST API default endpoint does not provide JSON-P // support, which '//js-api.evrythng.com' does. var url = Utils . buildUrl ( options ) ; // Return a promise and resolve/reject it in the callback function. return new Promise ( function ( resolve , reject ) { // Attach callback as a global method. Evrythng's REST API error // responses always have a status and array of errors. window [ uniqueName ] = function ( response ) { if ( response . errors && response . status ) { var errorData = _buildError ( url , response . status , params . method , response ) ; Logger . error ( errorData ) ; if ( errorCallback ) { Logger . warnCallbackDeprecation ( ) ; errorCallback ( errorData ) ; } reject ( errorData ) ; } else { if ( successCallback ) { Logger . warnCallbackDeprecation ( ) ; successCallback ( response ) ; } try { response = JSON . parse ( response ) ; } catch ( e ) { } resolve ( response ) ; } // Remove callback from window. try { delete window [ uniqueName ] ; } catch ( e ) { } window [ uniqueName ] = null ; } ; _load ( url , reject ) ; } ) ; }
Jsonp method sets prepares the script url with all the information provided and defines the callback handler.
Jsonp method sets prepares the script url with all the information provided and defines the callback handler .