I try to get JSON data from my web server but it doesn't work.
$.mobile.showPageLoadingMsg();
//$.getJSON('http://localhost:8000/'+site+'/?format=json&callback=?', {}, function(){alert();});
$.ajax({
url : 'http://localhost:8000/'+site +'/?format=json&callback=?',
type : 'GET',
dataType : 'jsonp',
jsonp : 'callback',
success : function(){alert('success');},
error : function(){alert('fail')}
});
$.getJSON, $.ajax two method's callback function didn't firing at all.
What's the problem?
My web server's code:
response_data.append({
'user_nickname' : post.user_nickname,
'title' : post.title,
'recommend' : post.recommend,
'oppose' : post.oppose,
'date' : str(post.date),
'hit' : post.hit,
'commentcount' : post.commentcount
})
return HttpResponse(simplejson.dumps(response_data), mimetype='application/json')
In the insepector, it returns get, 200, ok, so HttpResponse has no problem.
Here is response:
[{"hit": 5, "title": " \uc624\ud1a0\uc774\uc2a4\ucf00\uc774\ud551 \ub418\ub294\uac00", "commentcount": 0, "oppose": 0, "recommend": 0, "date": "2012-07-24 07:01:22.453000+00:00", "user_nickname": "\ud55c\uae00\ub85c\uc5bc\ub9c8\ub098\uae38\uac8c\uae4c\uc9c0\uac00\ub2a5\ud558\ub7ef\uc778\u3131\u3147\u3139\u3147\ub05d"}, {"hit": 4, "title": "\uc5ec\uae30 \uae00\uc4f0\uba74?", "commentcount": 1, "oppose": 0, "recommend": 0, "date": "2012-07-24 06:52:05.125000+00:00", "user_nickname": "\ud55c\uae00\ub85c\uc5bc\ub9c8\ub098\uae38\uac8c\uae4c\uc9c0\uac00\ub2a5\ud558\ub7ef\uc778\u3131\u3147\u3139\u3147\ub05d"}]
$.ajax() never fires the success callback function. it just calls error's alert('fail');