function resolveAsJSON()
    {
        // 1. if it’s not JSON…
        if (oXhr.getResponseHeader('Content-Type').indexOf('application/json') === -1)
        {
            fnReject(`Expecting JSON, got ${oXhr.getResponseHeader('Content-Type')}`);
            return;
        }

        // 2. try and convert stuff
        let oJson;
        try
        {
            oJson = JSON.parse(oXhr.responseText);
        }
        catch (TypeError)
        {
            fnReject('Could not parse response JSON');
            return;
        }

        // 3. success!
        fnResolve(oJson);
    }
/**
     * Tries to parse the response as JSON, and resolves/rejects suitably.
     */
Tries to parse the response as JSON, and resolves/rejects suitably.
Tries to parse the response as JSON and resolves / rejects suitably .
function resolveAsJSON()
    {
        if (oXhr.getResponseHeader('Content-Type').indexOf('application/json') === -1)
        {
            fnReject(`Expecting JSON, got ${oXhr.getResponseHeader('Content-Type')}`);
            return;
        }
        let oJson;
        try
        {
            oJson = JSON.parse(oXhr.responseText);
        }
        catch (TypeError)
        {
            fnReject('Could not parse response JSON');
            return;
        }
        fnResolve(oJson);
    }
function resolveAsJSON ( ) { if ( oXhr . getResponseHeader ( 'Content-Type' ) . indexOf ( 'application/json' ) === - 1 ) { fnReject ( ` ${ oXhr . getResponseHeader ( 'Content-Type' ) } ` ) ; return ; } let oJson ; try { oJson = JSON . parse ( oXhr . responseText ) ; } catch ( TypeError ) { fnReject ( 'Could not parse response JSON' ) ; return ; } fnResolve ( oJson ) ; }
Tries to parse the response as JSON, and resolves/rejects suitably.
Tries to parse the response as JSON and resolves / rejects suitably .
// 1. if it’s not JSON… // 2. try and convert stuff // 3. success!