yadav ajax,Django ajax error

I am getting an error while using AJAX to populate a table inside my django template. I am not sure what the error is, please help me in resolving this issue. I have shared all the important files, if I remove ajax and redirect the url to the destination URL then the code works fine, but somehow the ajax implementation is throwing an error.

Exception happened during processing of request from ('127.0.0.1', 64879)

Traceback (most recent call last):

File "c:\Python27\Lib\SocketServer.py", line 593, in process_request_thread

self.finish_request(request, client_address)

File "c:\Python27\Lib\SocketServer.py", line 334, in finish_request

self.RequestHandlerClass(request, client_address, self)

File "c:\Users\mayayadav\djcode\mysite\venv\lib\site-packages\django\core\serv

ers\basehttp.py", line 150, in __init__

super(WSGIRequestHandler, self).__init__(*args, **kwargs)

File "c:\Python27\Lib\SocketServer.py", line 651, in __init__

self.finish()

File "c:\Python27\Lib\SocketServer.py", line 710, in finish

self.wfile.close()

File "c:\Python27\Lib\socket.py", line 279, in close

self.flush()

File "c:\Python27\Lib\socket.py", line 303, in flush

self._sock.sendall(view[write_offset:write_offset+buffer_size])

error: [Errno 10053] An established connection was aborted by the software in yo

ur host machine

Views.py

def SearchTrips(request):

city=request.POST['city'].replace(" ","%20")

location=request.POST['location'].replace(" ","%20")

duration=request.POST['duration']

print city

print location

url="http://blankket-mk8te7kbzv.elasticbeanstalk.com/getroutes?city="+city+"&location="+location+"&duration="+duration

print url

x=urllib2.urlopen(url)

datas=json.load(x)

return render(request,'searchtrips.html',{'datas':datas})

Ajax.js

$(function(){

$("#routes").submit(function() {

$.ajax({

type: "POST",

url: '/searchtrips/',

data: {

'city' : $('#city').val(),

'location' : $('#location').val(),

'duration' : $('#duration').val(),

'csrfmiddlewaretoken': document.getElementsByName('csrfmiddlewaretoken')[0].value

},

success:searchSuccess,

datatype: 'html'

});

});

});

function searchSuccess(data, textStatus, jqXHR)

{

$('#routeTable').html(data);

};

searchtrips.html

{% for data in datas %}

{{ data.score}}

{%for element in data.place.elements%}

{{element.placeName}}

{% endfor %}

{% endfor %}

htmlfile

........................

{% csrf_token %}

Search

Score Cost

Itinerary

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值