query the data in this way
user_add1 = UserAddress.objects.filter(id=int(add_id))
then serialize
json_data = serializers.serialize("json", user_add1, ensure_ascii=False)
return json
return HttpResponse(json.dumps(json_data), content_type="application/json; charset=utf-8")
the front end receives json
how to remove [] parentheses?
[{"model": "Shopping.useraddress", "pk": 8, "fields": {"user": 3, "district": "", "address": "", "signer_name": "", "signer_mobile": "12345678901", "default_add": false, "add_time": "2018-03-29T14:32:35.552Z"}}]
how does the front end call json
alert (data.fields.address) to get no value
get the ID of the editing address and ajax it to the backend. For example, I click on the edit of id=9, but what I actually send back is how can id=7, return a different id?
<a onclick="modify()" id="modify" data-id="7" ><i class="am-icon-edit"></i></a>
<a onclick="modify()" id="modify" data-id="8" ><i class="am-icon-edit"></i></a>
<a onclick="modify()" id="modify" data-id="9" ><i class="am-icon-edit"></i></a>
function like() {
var tree = document.getElementById("delete");
var id = (tree.getAttribute("data-id"));
$.ajax({
cache: false,
type: "POST",
url:"{% url "address" %}",
data:{"add_id": id, "type": "delete"},
async: true,
beforeSend:function(xhr, settings){
xhr.setRequestHeader("X-CSRFToken", "{{ csrf_token }}");
},
success: function(data) {
if(data.status == "success"){
window.location.reload();
}
},
});
}