Reputation: 17234
var data;
$(document).ready(function(){
var rows = document.getElementById("orderlist_1").rows; var cell = rows[rows.length - 1].cells[3];
data = "id="+cell.innerHTML
checkAndNotify();
})
function checkAndNotify()
{
alert("oo");
$("#shownoti").load("/mostrecenttransaction","id=2008010661301520679");
t = setTimeout("checkAndNotify()",3000)
return true;
}
//$(document).ready(checkAndNotify())
In the above code, window with content is shown every 3 seconds when I open the webpage. But, the next line is as if its never executes. If I manually open the URL http://127.0.0.1:8000/mostrecenttransaction/?id=2008010661301520679 , it returns me a HttpResponse so why is the AJAX call never sent.
I have checked using Inspect Element of google chrome by going to the network tab & observed that even if alert("oo") is executes every 3 seconds, but ajax request is never sent. Can anyone help me out. I have spent so much time on but I am unable to figure it out. You can check the code simply by git clone & "git checkout counternoti". Code can be run simply by "python2 manage.py runserver", no configuration needed.(enter username as "123456789" and password as abcd It would be nice if if you could see it for yourself. At least, it damn interesting to me as a beginner.
My repo -> https://github.com/shadyabhi/pycourt_login/tree/counternoti
Related code in urls.py:(./urls.py)
(r'^mostrecenttransaction/',mostRecentTransaction),
views.py: (./views.py:line 339)
def mostRecentTransaction(request):
transactid_atdocument = request.GET['id'][7:]
latestid = Ordersss.objects.latest('transaction_id').transaction_id[7:]
print latestid, transactid_atdocument
if latestid > transactid_atdocument:
return HttpResponse("Food List outdated, please refresh")
else:
return HttpResponse("")
templates: (./templates/home.html:line 282)
<script type="text/javascript" src="/pycourt/newordernotification.js"></script>
..
..
<div id=shownoti"></div>
I am new to jQuery & AJAX and this thing has driven me crazy after I tried it for hours solving it. Main point is, if the "alert" is shown then why not the AJAX request? A reply would be highly appreciated.
Upvotes: 0
Views: 315
Reputation: 1450
jQuery.ajax({
url: "mostRecentTransaction",
type: "GET",
data: { id : 2008010661301520679 },
success: function(data) {
alert(data);
jQuery('#shownoti').html(data).hide().fadeIn(1500);
}
});
Upvotes: 4