无法将AJAX转换为Django [英] Can't Get AJAX to django

查看:63
本文介绍了无法将AJAX转换为Django的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的HTML是这样的:

My HTML is like this:

$.ajax({
    type: "GET",
    url:"/ajax/validate_supplier/",
    data:{
        'supplier_name': supplier_name
    },
    dataType: 'json'
});

我的django网址是这个:

My django url is this one:

   path('ajax/validate_supplier/', views.validate_supplier, name='validate_supplier'),

我的看法是这样

def validate_supplier(request):
    supplier_name= request.GET.get('supplier_name',none)
    data={
        'name_is': supplier_name
    }
    return JsonResponse(data)

这个简单的ajax get对我不起作用,我在做什么错?

This simple ajax get is not working for me, what am I doing wrong?

我收到404 Not found错误

I'm getting 404 Not found error

推荐答案

给出:-

{{url 'appname:validate_supplier'}}

您的问题是它将尝试转到您提供的网址,并且显示错误消息,指出该网址不存在.您通常可以在Chrome中按f12键以查看错误

the problem with yours is that it will try to go to the url you have given, and it will show error saying that the url does not exist. you can generally press f12 in chrome to see errors

这篇关于无法将AJAX转换为Django的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆