qq_35660280 2017-08-03 09:11 采纳率: 100%
浏览 1721
已结题

关于html5上传文件的一些错误的提问

第一种是: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(/&lt;/g,'<').replace(/&gt;/g,'>') 转换html标签,否则图片无法显示。
        if($("#feedback").children('img').length == 0) $("#feedback").append(data.replace(/&lt;/g,'<').replace(/&gt;/g,'>'));
        else $("#feedback").children('img').eq(0).before(data.replace(/&lt;/g,'<').replace(/&gt;/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

  • 写回答

10条回答

  • meicuojiushiwoi 2017-08-03 09:17
    关注

    你ajax的路径就这样??端口号没有??完整路径没有??

    评论

报告相同问题?

悬赏问题

  • ¥15 matlab有关常微分方程的问题求解决
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?
  • ¥100 求三轴之间相互配合画圆以及直线的算法
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable