I had a problem getting ajax post data from the django backend, I donβt know how to pass the value, please help.
In html, I just have the following:
<form id="get_vulns_from_family"> <label for="family_content">Enter a family name to display the NVTs</label> <input id="family_content" /> <input type="submit" value="search" /> </form>
In javascript, I wrote this:
$(function() { $("#get_vulns_from_family").submit(function(event) { var family_text = $("#family_content").val(); var family_data = {"family": family_text}; $.ajax({ url: "/template_conf/get_vulns_from_family", type: "POST", data: family_data, success: function(response) { console.log(response); }, error: function(response) { console.log("failed!"); } });
In the Django method corresponding to url /template_conf/get_vulns_from_family , I tried this:
def get_vuln_from_family(request): family = request.POST['family']
But django said: MultiValueDictKeyError: "Key 'family' not found in <QueryDict: {}>" , which means the POST dictionary is empty. Am I using the wrong way to retrieve data for publication? If so, what should I do? Thanks.
source share