Why is alert not run even though $.getJSON runs fine? (Callback not executed, even though the reques
Posted
by Emre Sevinç
on Stack Overflow
See other posts from Stack Overflow
or by Emre Sevinç
Published on 2010-05-06T10:07:59Z
Indexed on
2010/05/06
10:18 UTC
Read the original article
Hit count: 250
I have a snippet of code such as:
$.getJSON("http://mysite.org/polls/saveLanguageTest?url=" + escape(window.location.href) + "&callback=?",
function (data) {
var serverResponse = data.result;
console.log(serverResponse);
alert(serverResponse);
});
It works fine in the sense that it makes a cross-domain request to my server and the server saves the data as I expect. Unfortunately, even though the server saves data and sends back a response I just can't get any alert or the console.log run. Why may be that? The server side code is (if that is relevant):
def saveLanguageTest(request):
callback = request.GET.get('callback', '')
person = Person(firstName = 'Anonymous',
ipAddress = request.META['REMOTE_ADDR'])
person.save()
webPage = WebPage(url = request.GET.get('url'))
webPage.save()
langTest = LanguageTest(type = 'prepositionTest')
langTest.person = person
langTest.webPage = webPage
langTest.save()
req ['result'] = 'Your test is saved.'
response = json.dumps(req)
response = callback + '(' + response + ');'
return HttpResponse(response, mimetype = "application/json")
What am I missing? (I tried the same code both within my web pages and inside the Firebug and I always have the problem stated above.)
© Stack Overflow or respective owner