主要是view中的函數可以直接返回,作為http的response:
view中:
return JsonResponse({'pathname': pathName, 'polygon': json.dumps(originGpxManager.GetPolygon(pathName))})
template中:
//send to servers
function reqListener() {
console.log(typeof(this.responseText),typeof(this.response));
console.log(this)
var response = JSON.parse(this.responseText);
console.log(response);
var pathName = decodeURI(response['pathname']);
var polygon = response['polygon'];
console.log('pathName', pathName);
//add polygon to gpxmanager
pathManger.AddOriginPolygon(pathName, polygon);
}
var oReq = new XMLHttpRequest();
oReq.addEventListener("load", reqListener);
oReq.open("GET", 'decodePathLine_toPolygon' + '/'+pathname+'/' + str_paths);
oReq.send();