使用Django和Python创建JSON响应
/* RECEIVE VALUE */$validateValue=$_POST['validateValue'];$validateId=$_POST['validateId'];$validateError=$_POST['validateError'];/* RETURN VALUE */$arrayToJs = array();$arrayToJs[0] = $validateId;$arrayToJs[1] = $validateError;if($validateValue =="Testuser"){ // Validate?? $arrayToJs[2] = "true"; // RETURN TRUE echo '{"jsonValidateReturn":'.json_encode($arrayToJs).'}'; // RETURN ARRAY WITH success}else{ for($x=0;$x<1000000;$x++){ if($x == 990000){ $arrayToJs[2] = "false"; echo '{"jsonValidateReturn":'.json_encode($arrayToJs).'}'; // RETURNS ARRAY WITH ERROR. } }}
def validate_user(request): if request.method == 'POST': vld_value = request.POST.get('validateValue') vld_id = request.POST.get('validateId') vld_error = request.POST.get('validateError') array_to_js = [vld_id, vld_error, False] if vld_value == "TestUser": array_to_js[2] = True x = simplejson.dumps(array_to_js) return HttpResponse(x) else: array_to_js[2] = False x = simplejson.dumps(array_to_js) error = 'Error' return render_to_response('index.html',{'error':error},context_instance=RequestContext(request)) return render_to_response('index.html',context_instance=RequestContext(request))
慕斯709654
慕勒3428872
ibeautiful
相关分类