サーバーからhtmlを取得するためにajax呼び出しを使用するアプリケーションに取り組んでいます。サーバーで実行すると、すべて正常に動作します。
しかし、ローカルホストで実行していると、'Access-Control-Allow-Origin' エラーが発生します。私は周りを見回しましたが、jsonpを使用することが解決策になるようです。
したがって、私の ajax 呼び出しは次のようになります。
$.ajax({
url: url,
dataType: 'jsonp',
crossDomain: true,
type: 'GET',
success: function(data){
// should put the data in a div
},
error: function(){
//do some stuff with errors
}
});
サーバーから html を取得しますが、常に次のエラーが発生します。
Uncaught SyntaxError: Unexpected token <
jsonp 応答を html でラップする方法はありますか?
ありがとう!