Featured post
jQuery getJSON Output using Python/Django -
so, i'm trying make simple call using jquery .getjson local web server using python/django serve requests. address being used is:
http://localhost:8000/api/0.1/tonight-mobile.json?callback=jsonp1290277462296
i'm trying write simple web view can access url , return json packet result (worried actual element values/layout later).
here's simple attempt @ alerting/returning data:
$.getjson("http://localhost:8000/api/0.1/tonight-mobile.json&callback=?", function(json){ alert(json); <!--$.each(json.items, function(i,item){ });--> });
i able access url directly, either @ http://localhost:8000/api/0.1/tonight-mobile.json or http://localhost:8000/api/0.1/tonight-mobile.json&callback=jsonp1290277462296 , get valid json packet... i'm assuming it's in noob javascript:)
my views.py function generating response looks follows:
def tonight_mobile(request): callback = request.get.get('callback=?', '') def with_rank(rank, place): return (rank > 0) place_data = dict( places = [make_mobile_place_dict(request, p) p in place.objects.all()] ) xml_bytes = json.dumps(place_data) xml_bytes = callback + '(' + xml_bytes + ');' return httpresponse(xml_bytes, mimetype="application/json")
with corresponding urls.py configuration:
(r'^tonight-mobile.json','iphone_api.views.tonight_mobile'),
i still confused on how use callbacks, maybe issue lies. note able call directly 'blah.json' file giving me response, not through wired url. assist me direction?
first, callback = request.get.get('callback=?', '')
won't value of callback
.
callback = request.get.get( 'callback', none )
works better.
to debug kind of thing. might want include print
statements in django view function can see what's going on. example: print repr(request.get)
helpful thing put in view function can see dictionary.
- Get link
- X
- Other Apps
Comments
Post a Comment