Ajax请求跨端口问题的描叙及解决
phfile项目结构: view里的接口定义: 以8080启动phfile项目. {"status": 0,"data": "上传的图片名错误"}
还有一个phfile2的项目,和phfile项目基本一样,phfile2里有个task.html, "url": "http://127.0.0.1:8080/test/","data": params,"type": 'POST',"dataType": 'json',"success": function (data) {
if (data.status == 1) {
alert("上传成功");
location.reload(true);
} else {
alert('上传失败:'+data.data);
}
$('#file_modal').modal('hide');
},"error": function (xhr,status,error) {
alert("上传错误:" + error);
$('#file_modal').modal('hide');
}
以8000启动phfile2项目. 调用结果: test>>>>>>>>>>>>>>......
[31/Oct/2016 20:22:21] "POST /test/ HTTP/1.1" 200 73
3,将test方法从phfile移动到phfile2,将调用url改成:”url”: “http://127.0.0.1:8000/test/“后, 原因: 2.ajax访问时session为null(该原因已排除) 解决: @csrf_exempt
def test(request):
response=HttpResponse(json_encode({"status":0,"data":"上传的图片名错误"}))
response["Access-Control-Allow-Origin"] = "http://127.0.0.1:8000"
print "test>>>>>>>>>>>>>>......"
return response
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |