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和jsonp的区别
http://kb.cnblogs.com/page/139725/