Python — запрос Django не передается в AJAX в формате JSON

и в JS

var patch = {'function_name': function_id} $.ajax( { url: url, dataType: "json", data: patch, success: function (data) { console.log('success') $("#id_script_location").val(data); }, error: function(jqXHR, textStatus, errorThrown) { console.log('jqXHR:'); console.log(jqXHR); console.log('textStatus:'); console.log(textStatus); console.log('errorThrown:'); console.log(errorThrown); } }); console.log("ajax executed") }); 

views.py

 import json def load_script(request): if request.method == 'POST': response_json = request.POST response_json = json.dumps(response_json) data = json.loads(response_json) query = data['function_name'] data ={'query': query} return JsonResponse(data, safe=False) 

Понравилась статья? Поделиться с друзьями:
JavaScript & TypeScript
Adblock
detector