以下のようなHTMLで検証したのですが通常エラーが出なかったのですが、getJSONを挟んでからエラーが出るようになってしまいました。
なぜでしょうか?
HTML
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <p>take</p> <script type="text/javascript"> var title ; var content ; function syncGetJSON() { // var dfd = new $.Deferred // dfd.resolve("title","content"); // return dfd.promise(); // => エラーは出ない var dfd = new $.Deferred $.getJSON(`http://localhost:3000/api/alc.json?word=hazy`, function(data) { title = data.title content = data.content dfd.resolve(title,content); return dfd.promise(); }); }; syncGetJSON().then( function(title,content) { console.log(title,content) } ); </script>
エラー
Uncaught TypeError: Cannot read property 'then' of undefined at eval (eval at <anonymous> (index:72), <anonymous>:2:14) at index:101
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。