javascript - How do i read multiple json objects in django using POST method -
i sending multiple json object server , django views how multiple json objects , extracting each key value.
<html> <head> <link rel="stylesheet" href='/static/js/file.txt' type="text/css"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script> <script> $(document).ready(function() { $.get('static/js/file.txt', function (data) { var lines = data.split("\n"); var dict = {}; $.each(lines, function (n, elem) { var fields = elem.split("\t"); var service_id = fields[0]; dict[fields[0]] = {'owner':fields[1],'email':fields[2],'phone':fields[3], 'model':fields[4],'date':fields[5],'problem':fields[6]}; }); var jsonobj = json.stringify(dict); //console.log(dict); $.ajax({ type: 'post', url: 'load/data/', datatype: 'json', data: {simple:jsonobj, csrfmiddlewaretoken: $('input[name=csrfmiddlewaretoken]').val()}, contenttype: 'application/json', success: function (json) { $("#simple").append("<p>" + json + "</p>"); } }); }); }); </script> </head> <div id ="simple"></div> </html>
Comments
Post a Comment