私はjQueryの非常に奇妙な振る舞いのように思われることに髪を引っ張っています。
define ['jquery', 'models/ConfigModel'], ($, ConfigModel) ->
class MyController
initialize: () ->
confData = $.getJSON('/config.json', (data) -> console.log data)
これは問題なく機能します。config.jsonのコンテンツを返します
define ['jquery', 'models/ConfigModel'], ($, ConfigModel) ->
class MyController
initialize: () ->
confData = $.getJSON
url: '/config.json'
success: (data) -> console.log data
これにより、index.htmlのコンテンツが返されます。これは、サーバーの.htaccessファイルが原因である可能性があります。
RewriteEngine On
RewriteRule ^(js|css|media|api|pie|templates|config.json) - [L,NC]
RewriteCond %{REQUEST_FILENAME} !index.html
RewriteRule .* index.html [QSA,L]
ChromeコンソールでJSを使用してみましたが、同じ結果が得られました。
//works well
$.getJSON('/config.json', function(data) {console.log(data)})
//index.html
$.getJSON({url:'/config.json', success: function(data) {console.log(data)}})
私には回避策があるので、このような状況をデバッグする方法に関する他の人の考えよりも、解決策の重要性は低くなります。
編集:
$.getJSON({url:'/config.json', success: function(data) {console.log(data)}})
XHR finished loading: "http://site.dev/[object%20Object]]".
$.getJSON('/config.json', function(data) {console.log(data)})
XHR finished loading: "http://site.dev/config.json".