ä»æ¥ããã£ãã®ã§ãã¡ã¢ä»£ããã«æ®ãã¦ããã¾ãã
ï¼ããããä¸ãæ¸ãã¦ã¦æ°ä»ãããã©ãæ®éã«æåã³ã¼ãã®åé¡ã ããããããªå¤§å±¤ãªæ¡ä»¶ã«ããªãã¦ãè¯ãã£ãã¨æã£ããã©ããã£ããæ¸ããã®ã§æ®ãã¦ããã¾ããèªãã®æ ãã¦è§£æ±ºçã ãç¥ããã人ã¯ä¸çªä¸ã¾ã§è¡ã£ã¦ãé¢é£è¨äºãèªã¿ã¾ããããï¼
è²ã
ãã£ã¦$.getScript()
ãå©ç¨ãã¦ããããåãã¨ã©ã¼ãåºãæã«å¤æ°ãUndefinedã ã¿ãããªæãã ã£ãã®ã§ããªãã ããï¼ï¼ã¨æã£ã¦åå ã¨ãæ¢ã£ãã®ã§æ¸ãã¦ããã¾ãããåºæ¬ã¯ãã ã®æååãã§ãããããããã±ã¼ã¹ãããã£ã¦ãã¨ã§ãä»ã«åãäºä¾ã«ã¶ã¤ãã£ã人åãã§ãã
çºçæ¡ä»¶ã¨äºè±¡ã«ã¤ãã¦
çºçæ¡ä»¶ã¯ããªãéããã¦ãã¦ã以ä¸ã®4ã¤ãå ¨ã¦æºããå ´åã«èµ·ããã¨ã©ã¼ã«ã¤ãã¦æ¸ãã¾ãã
$.getScript
ã§jsãèªã¿è¾¼ãã§ãã1.
ã§èªã¿è¾¼ãjsãSJISã§è¨è¿°ããã¦ãã- jså ã®ã³ã¡ã³ãã®è¡æ«ãå ¨è§æåã§çµãã£ã¦ãã
- Internet Explorerã§ã¢ã¯ã»ã¹ãã¦ãã
ç¾è±¡ã¨ãã¦ã¯ãã³ã¡ã³ãã®çµãããã¨ã³ã³ã¼ãã®é¢ä¿ã§æ£å¸¸ã«å±éããããIEã§JavaScriptå®è¡ã¨ã©ã¼ãèµ·ãã¾ãã
ä¸èº«ã
// ã³ã¡ã³ãã§ã var t = 'a'; alert(t);
ã
/* ã³ã¡ã³ãã§ã */ var t = 'a'; alert(t);
ã®ãããªSJISã®jsãã¡ã¤ã«ã$.getScript()
ã§èªã¿è¾¼ãã¨åç¾ããã¾ãã
åé¿ç
åè¿°ã®æ¡ä»¶ã1ã¤ã§ãåé¿ããã°è¯ãã§ãã
ãããã¨ãªãçç±ããªãéãã$.getScript()
ã使ããªãã¨ãããªããã¨ã«ã¯ãªããªãã¨æãã®ã§ãç´ ç´ã«<script>
ããã¥ã¼ã«æ¸ããããããç¡çãªãã
$('<script>').attr('src','example.js').appendTo('head')
ã¨ãã£ã¦æ¸ããæ¹ãè¯ãã§ããã©ããã¦ããã¼ããããå ´åã¯$.ajax()
ãå©ç¨ãã¦ãå¾è¿°ã®ãµã¤ãã§ç´¹ä»ããã¦ããæ¹æ³ã§xhr.overrideMimeType()
ã«æåã³ã¼ããè¨å®ãã¦ããã¨è¯ãã§ãã
åå ã¯å¾è¿°ãã¾ãããjsãã¡ã¤ã«ã®æåã³ã¼ããUTF-8ã«ãã¦ã解決ãã¾ãããã³ã¡ã³ãã®è¡æ«ãå ¨è§æåã§ãªããã¦ã解決ãã¾ãã
åå
jQueryã®$.getScript
ã®å®è£
é¨åãjQuery ver2.0.3ã®ã½ã¼ã¹ã³ã¼ãããå¼ç¨ãã¾ãã
getScript: function( url, callback ) { return jQuery.get( url, undefined, callback, "script" ); }
ããã§å¼ã°ãã¦ããjQuery.get
ã¯jQuery.ajax
ãå©ç¨ãã¦ãã¾ãã
jQuery.each( [ "get", "post" ], function( i, method ) { jQuery[ method ] = function( url, data, callback, type ) { // shift arguments if data argument was omitted if ( jQuery.isFunction( data ) ) { type = type || callback; callback = data; data = undefined; } return jQuery.ajax({ url: url, type: method, dataType: type, data: data, success: callback }); }; });
$.ajax
ã§ã¯èªã¿è¾¼ã¿å
ã®ãã¡ã¤ã«ã®æåã³ã¼ããUTF-8ã¨ãã¦èªã¿è¾¼ãã§ãã¾ãã®ã§ããããåå ã«ãªã£ã¦ãã¾ãã
ææ°è¾¼ãã§ããã°è¨äºã«ãããã©ãæ¬å½ã«ãã ã®æåã³ã¼ãã®ã¢ã¬ã§æååãããã£ã¦ã ãã®è©±ã ãããããªå¤§å±¤ã«ããªãã¦ããã£ããªã£ã¦ãã£ã¡ãå¾æãã¦ãã¾ããçµããã
åèæç®
- jQueryのloadで文字化けする場合の対処 | Smart
xhr.overrideMimeType()
ã«æåã³ã¼ããæå®ãã¦ãããã°è§£æ±ºããã¨ãã話
- メモ: IEでもできた! jQuery.ajaxでShift JIS(sjis)の外部HTMLを読み込む時の文字化け回避方法
- .htaccessã§
AddDefaultCharset Shift_JIS
ã¨ãã話
- .htaccessã§