Created
July 27, 2016 21:32
This file contains 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
views.py | |
import json | |
from django.http import HttpResponse | |
def startpage(request): | |
return render_to_response('Main.html'); | |
def index(request): | |
platforms = Platform.objects.select_related().values('platformtype') | |
return HttpResponse(json.dumps(list(platforms))) | |
# return HttpResponse(json.dumps(platforms)) # one value | |
js code | |
function GetPlagtform() { | |
$.ajax({ | |
type: "GET", | |
url: "/api/platform.json", | |
contentType: "application/json;charset=utf-8", | |
dataType: "json", | |
cache: false, | |
success: function (result) { | |
$.each(result, function (i, value) { | |
$('#platformList').append( | |
$('<option></option>').val(value.platformtype).html(value.platformtype) | |
); | |
}, | |
error: function (response) { | |
alert('error'); | |
} | |
}); | |
} | |
code not tested. | |
imitation google maps struct example | |
var data = {"offers": [{"address": "city 1", "name": "Apartment 1", "lat": "48.967", "code": "11111", "lng": "7.4639"}, {"address": "city 2", "name": "Apartment 2", "lat": "48.964", "code": "22222", "lng": "7.470"}, ... | |
func | |
def show_all_json_geo(request): | |
geo_obj = Offer.objects.select_related().values( | |
'name', | |
'address', | |
'lat', | |
'lng', | |
'code', | |
) | |
offers = {'offers': list(geo_obj)} | |
return HttpResponse("var data = " + json.dumps(offers)) # work, simple imitation. | |
html load data variable | |
<script src="/json/geo.json"></script> | |
in js code use as data | |
for (var i = 0; i < 100; i++) { | |
var dataPhoto = data.offers[i]; | |
... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment