第一种是:jquery+ajax,每次上传的时候,显示这个错误,是不是我的url写得有问题,应该怎么写
Failed to load resource: the server responded with a status of 405 (Not Allowed)
index.html:1 XMLHttpRequest cannot load http://localhost/. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access. The response had HTTP status code 405.
下面是我的代码
$(".loading").show(); //显示加载图片
//发送数据
$.ajax({
url:'http://localhost',
type:'POST',
data:data,
cache: false,
contentType: false, //不可缺参数
processData: false, //不可缺参数
success:function(data){
data = $(data).html();
//第一个feedback数据直接append,其他的用before第1个( .eq(0).before() )放至最前面。
//data.replace(/</g,'<').replace(/>/g,'>') 转换html标签,否则图片无法显示。
if($("#feedback").children('img').length == 0) $("#feedback").append(data.replace(/</g,'<').replace(/>/g,'>'));
else $("#feedback").children('img').eq(0).before(data.replace(/</g,'<').replace(/>/g,'>'));
$(".loading").hide(); //加载成功移除加载图片
},
error:function(){
alert('上传出错');
$(".loading").hide(); //加载失败移除加载图片
第二个问题是类似的:也是没有上传成功,我只需要有一个能上传成功就行了,我觉得可能是我的url有问题,但这就是我的ip地址
错误显示:
Failed to load resource: the server responded with a status of 403 (Forbidden)
index.html:1 XMLHttpRequest cannot load http://192.168.1.137/. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access. The response had HTTP status code 403.
我的代码如下:
var xhr = new XMLHttpRequest();
.....(中间代码省略就不贴上来了)
xhr.open('post', 'http://192.168.1.137',true);
xhr.onreadystatechange = function () {
alert(xhr.readyState);//FF下会依次是1,2,3,4但最后还会再来个1
//IE下则是1,1,3,4
};
xhr.send(fd);
假设我的ip地址为192.168.1.xxx,然后我想把文件传输到我的/home/hhh/aaa目录下,我应该怎么写url
你ajax的路径就这样??端口号没有??完整路径没有??
我不太懂哈,首先405我觉得你的请求方式是不是不对啊,然后你的url我看着也有点蒙,没见过这样的,那个是要请求什么
1、断点下看是否进入到后台代码;
2、你的data中是否是file,是否正确;
3、jQuery有上传文件的插件,
403 ,405 不是路径问题,403,权限不够,405访问被禁止 ,报错是显示Access-Control-Allow-Origin .跨域了,
易源的QQ测运势为例:
var HOST = "http://route.showapi.com/";
var STORY = "863-1";
function loadData() {
//parm必传参数
var parm = "showapi_appid=42229&showapi_sign=eb56965af61e40fd90f7e43537f38877&qq=979598425";
var requst = new XMLHttpRequest();
requst.open("GET",HOST+STORY+"?"+parm,false);
requst.onload = function () {
var result = JSON.parse(requst.response);
console.log(result);
var container = document.querySelector(".container");
var content = "<h3>"+result.showapi_res_body.analysis+"</h3><p>"+result.showapi_res_body.desc+"</p>";
container.innerHTML = content;
};
requst.send();
}
loadData();
我上传文件都是用的表单 ajax上传,表单用于选择文件,提交方式是ajax 下面可以参考
http://yunzhu.iteye.com/blog/2177923
获取本地文件
function loadData() {
requst.open("GET",'文件路径');
requst.onload = function () {
console.log(result.response);
};
requst.send();
}
loadData();
我也是菜鸟 哈哈哈
url:'http://localhost', 这个地址不全啊
我看到你传的数据是个变量叫data,然后回调也是data,那么问题来了,success里面到底是什么鬼
url:'http://localhost', 这个地址。。。 也是醉了