django AJAX POST请求显示500错误?

时间:2016-09-06 06:18:29

标签: jquery ajax django

我的ajax代码是

   $(function(){    
        $('#search').keyup(function(){
        $.ajax({
       type:"POST",
       url:"/abc/search/",
       data:{'search_text':$('#search').val(),
              'csrfmiddlewaretoken' : $("input[name=csrfmiddlewaretoken]").val(),
       },
       success: searchsuccess,
       datatype: 'html'
     });
   });
 });

 function searchsuccess (data, textStatus, jqXHR){
 $('#search_result').html(data);
}

我的观点是

def search_college(request):
if request.method == 'POST':
    search_text=request.POST['search_text']
else:
    search_text = ""
colleges = Collage.objects.filter(col_name__contains=search_text)
render(request, "ajax_search.html", {'colleges': colleges})

我的表格是 -

             <form>{% csrf_token %}
            <input type="text" id="search" name="search">
            </form>

ajax post call后我是500(内部服务器错误)?我怎么解决呢?

0 个答案:

没有答案