chromeのバージョンを31から36にアップデートしたら
別ドメインから
GoogleAppsScript.ContentServiceのJSONPが取得出来なくなった。
function doGet(e){
var _c = e.parameter.callback;
var _s = JSON.stringify({test:'hogehoge'});
_s = ((_c)?_c + '(' + _s + ')':_s);
return ContentService.createTextOutput(_s).setMimeType(ContentService.MimeType.JSON);
}
別サイトのHTML
<!DOCTYPE html>
<html ng-app="MyApp">
<head>
<script src="https://code.angularjs.org/1.3.0-beta.5/angular.js"></script>
<script src="script.js"></script>
</head>
<body>
<div ng-controller="formCtrl">
<form ng-submit="submit();">
<button type="submit" />
</form>
<p>{{items|json}}</p>
</div>
</body>
</html>
angular.module("MyApp", [])
.controller("formCtrl", function($http, $scope){
$scope.submit = function(){
$http.jsonp('https://script.google.com/macros/s/xxxxxxxxxxxxxxxxxxxxxx/exec',{params:{callback:"JSON_CALLBACK",action:"hogehoge"}})
.success(function(data, status){
$scope.items = angular.fromJson(data);
})
.error(function(data, status, headers, config){
console.log('error');
});
};
});
Angularjsのバージョンは1.3.0-beta.5
Chromeのコンソールログから出力されるエラーはこんな感じ。
Refused to execute script from 'https://script.google.com/macros/s/xxxxxxxxxxxxxxxxxxxxxx/exec?action=hogehoge&callback=angular.callbacks._0' because its MIME type ('application/json') is not executable, and strict MIME type checking is enabled.
バージョンアップする度いつもなにかと悩んでるような気が・・・。う~む。
Chrome31ではJSONPでGASのJSONを取得出来ていたのでちと困った。
一日かかっていろいろと調べた結果、結局ブラウザのMIMETYPEがより厳密にチェックが入ったんだろうというオチに。
ContentService.createTextOutput(jsonp).setMimeType(ContentService.MimeType.JSON);
↓
ContentService.createTextOutput(jsonp).setMimeType(ContentService.MimeType.JAVASCRIPT);
GAS側でMimeTypeをJAVASCRIPTにしたら解決。