我想知道是否可以使用ajax在新网页上加载一些数据,我已经在python代码下面编写了从数据库获取数据的代码。预先谢谢你。
function display_specs(name){
$(document).ready(function(){
$.ajax({
url: "{% url 'load_product' %}",
type: "POST",
data: { csrfmiddlewaretoken: '{{ csrf_token }}' ,"imodel":name},
async: false,
});
});
}
def load_product(request):
imodel = request.POST.get('imodel')
usernames = database.child("Items").get()
for user in usernames.each():
userid = user.key()
dtls = database.child("Items").child('details').child(userid).child('iname').get().val()
if dtls == imodel:
dtls1 = database.child("Items").child('details').child(userid).child('idesc').get().val()
data2 = {"iname":imodel,"imodel":dtls1}
data = {}
data['msg'] = 'success22'
return HttpResponse(json.dumps(data), content_type="application/json")