Ajaxのドメイン横断要求
1213 ワード
1)フロントエンドAjax部分コード
function changeClass(){
$.ajax({
url: 'http://192.168.1.107:9000/main_page/front/data', //
async: false,
dataType: 'jsonp',
type:'get',
jsonp:"callback", // jsonp
jsonpCallback:"callback",
success: function (json_str) {
object_js = json_str;
//document.write(object_js);
showAllList();
}
});
}
2)バックエンドのルート部分コード@main_page_Blueprint.route('/front/data')
def front_data():
Class = BaseClass(class_number)
list_sign_students = Class.list_sign_students
list_unsign_students = Class.list_unsign_students
dic_all_students = {}
for student in list_sign_students:
dic_all_students[student] = 1
for student in list_unsign_students:
dic_all_students[student] = 0
jsonp = 'callback' + '(' + str(dic_all_students ) + ')' # callback , json
return jsonp
3)リンクを付けて、jsonとjsonの違いを説明する。http://kb.cnblogs.com/page/139725/