jerrygarciuh
jerrygarciuh

Reputation: 21988

If dataType is JSON why would MIME type 'application/json' be rejected?

I had thought that if dataType was specified as JSON that jQuery therefore expects a JSON response. Is that correct? http://api.jquery.com/jquery.ajax/ seems clear on the point.

In the function below I have tried specifying no dataType (for jQuery "Intelligent Guess") and explicitly to JSON (as seen below).

Both result in "Refused to execute script from [SNIP] because its MIME type ('application/json') is not executable, and strict MIME type checking is enabled."

This function previously worked for some years so either jQuery version changes or the headers sent from the API server must be causing?

How do I adjust so the sent MIME type 'application/json' is accepted?

function refresh() {
    $.post('https://api.example.com/api/v1/screenshot/create?callback=?',
        {
            'url': 'http://example.org/reports_scorecard_blank_HTMLMAKER.php?CTN=' + $('#CTN').val(),
            'dataType': "json",
            'size': 'page',
            'key': 'MY_KEY_HERE',
            'screen_width': 1900,
            'flash_delay' : 0,
            'delay' : 0,
            'instance_id' : 65,
        },
        function(remote, textStatus) {
            console.dir(remote);
            console.log('textStatus '+textStatus);
            if (remote.error) {
                clearInterval(interval);
                $('#cardMaking').hide();
                $('#error').html(remote.error).show();

                return;
            }

            if (textStatus != 'success') {
                setTimeout(function() { refresh(); }, 5 * 1000);
                return;
            }

            if (remote.queue == 0) {
                $('#cardMaking').html('DONE!');
            }
            else if (remote.queue == 1) {
                $('#cardMaking').html('< 1 minute');
            }
            else if (remote.queue > 1) {
                $('#cardMaking').html('< ' + remote.queue + ' minutes');
            }


            if (remote.status == 'finished') {
                clearInterval(interval);

                $('#final_url').html( '<i>' + (remote.final_url || $('#url').val()) + '</i>');
                $('#summary').show();
                link = 'SOME_HTML_HERE';
                $('#cardMaking').html(link);

                // now fetch image
                $.post('reports_scorecard_blank_IMAGE_FETCHER.php',
        {
            'remote_id': remote.id,
            'CTN': $('#CTN').val()
        }, function(data) {
            console.log("Fetcher response: " + data);
                }
                );

            }
            }, 'json'
    );
}

Upvotes: 1

Views: 730

Answers (1)

Quentin
Quentin

Reputation: 943556

You've included callback=? in the URL which overrides everything else and causes jQuery to make a JSONP GET request instead of an XHR POST request.

Upvotes: 3

Related Questions