Last active
August 29, 2015 14:10
-
-
Save bekatom/85e838446111850eb96f to your computer and use it in GitHub Desktop.
django & JS client >json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function get_hotel_price(id){ | |
| $.ajax({ | |
| data : { 'id' : id}, | |
| type : 'GET', | |
| url : '/hotels/price/', | |
| success : function(responce){ | |
| rs = JSON.parse(responce); | |
| $('#id_price').val(rs.price); | |
| } | |
| }); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from django.shortcuts import HttpResponse | |
| from django.contrib.auth.decorators import login_required | |
| @login_required() | |
| def get_hotel_price(request): | |
| id = request.GET['id'] | |
| if id is not None: | |
| h = Hotels.objects.get(pk=id) | |
| data = {'price': h.price} | |
| return HttpResponse(json.dumps(data)) | |
| ##### URL ############# | |
| hotels_urlpatters = [ | |
| url(r'^price/$', get_hotel_price), | |
| ] | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment