시간 내 주셔서 감사합니다.Sammy.js가 Django 앱에 JSONP 요청을 렌더링하지 않습니다.
프런트 엔드에 Sammy.js가 있고 뒤쪽에 장고가있는 하이브리드 앱을 만들고 있습니다. 내 사이트는 CloudFront를 통해 S3에 호스팅 된 하나의 index.html이며, 숙제가 아닙니다.
"#/projects"경로 범주의 목록을 렌더링하고 싶습니다. 다른 도메인에서 실행되는 내 장고 백엔드에 대한 JSONP 요청.
내 장고보기 :
def get_categories(request):
jsoncallback = request.GET.get('jsoncallback')
data = {'categories': [{'name': c.name, 'slug': c.slug} for c in categories]}
jsonp = '{0}({1});'.format(jsoncallback, data)
response = json.dumps(jsonp, ensure_ascii=False)
return HttpResponse(response, content_type='application/json')
내 새미의 경로 :
(function($) {
var app = $.sammy('#app', function() {
// (default route here)
this.get('#/projects', function(context) {
// localhost via manage.py runserver
$.getJSON('http://localhost:8000/projects/categories/?jsoncallback=?',
null, function(categories) {
$.each(categories, function(i, category) {
console.log('here');
// code to render template here
});
});
});
$(function() {
app.run('#/');
});
})(jQuery);
방화범 내 장고보기로 호출의 응답 부분은 다음과 같습니다
"jQuery183018328394494212097_1372132674985({'categories':
[{'name': u'Open Source', 'slug': u'open-source'},
{'name': u'Web Development', 'slug': u'web-development'},
{'name': u'Print', 'slug': u'print'}]});"
하지만, 내 console.log
진술에 도달하지 못했습니다. 내가 뭘 잘못하고 있는지 모르겠다. 누군가 올바른 방향으로 나를 가리킬 수 있습니까? 불행히도 몇 시간 동안 웹에서 JSONP 예제를 여러 번 사용해 보면 도움이되지 않습니다.