0
여러 json 객체를 서버로 보내고 django가이 여러 json 객체를 얻고 각 키 값을 추출하는 방법을 보여줍니다.POST 메서드를 사용하여 django에서 여러 json 객체를 읽는 방법
여러 json 객체를 서버로 보내고 django가이 여러 json 객체를 얻고 각 키 값을 추출하는 방법을 보여줍니다.POST 메서드를 사용하여 django에서 여러 json 객체를 읽는 방법
<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>