Web サーバーから JSON データを取得しようとしましたが、うまくいきません。
$.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
2 つのメソッドのコールバック関数がまったく起動しませんでした。どうしたの?
私のウェブサーバーのコード:
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')
get
インスペクタでは, 200, okと返ってくるのでHttpResponse
問題ありません。
応答は次のとおりです。
[{"ヒット": 5, "タイトル": "\uc624\ud1a0\uc774\uc2a4\ucf00\uc774\ud551\ub418\ub294\uac00", "コメント数": 0, "反対": 0, "推奨" : 0、「日付」:「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"}, {"ヒット": 4, "タイトル": "\uc5ec\uae30 \uae00\uc4f0\uba74?", "コメント数" : 1, "反対": 0, "推奨": 0, "日付": "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()
成功のコールバック関数を起動することはありません。エラーを呼び出すだけですalert('fail');