标签:otto 跨域请求 request 请求 https ica head sync 解决
pip install django-cors-headers
内容详见:https://github.com/ottoyiu/django-cors-headers
使用Ajax获取json数据时,使用JSONP,JSONP只能用于GET请求,红色部分是注意事项
$.ajax({ url:‘http://localhost:8000/hello/‘, data:data, type : ‘GET‘, async : true, contentType: "application/json; charset=utf-8", dataType : ‘jsonp‘, jsonp:"callback", jsonpCallback:"success_jsonpCallback", success: function(data){ if (data.data) { alert(true); } else { return; } } , error:function(e){ alert(‘error‘); } });
后台代码:
def hello(request): lst=you_get.main(repo_path="" + _filepath + "", opt=‘-u‘, url="http://v.youku.com/v_show/id_XMjg4MTUwNjEzNg==.html") data={"data":lst} import json ljson=json.dumps(data) result = "success_jsonpCallback(" + ljson + ")"; response = HttpResponse(result) return response
标签:otto 跨域请求 request 请求 https ica head sync 解决
原文地址:http://www.cnblogs.com/shurua/p/7198442.html