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 C++使用Gunplot
  • ¥15 这个电路是如何实现路灯控制器的,原理是什么,怎么求解灯亮起后熄灭的时间如图?
  • ¥15 matlab数字图像处理频率域滤波
  • ¥15 在abaqus做了二维正交切削模型,给刀具添加了超声振动条件后输出切削力为什么比普通切削增大这么多
  • ¥15 ELGamal和paillier计算效率谁快?
  • ¥15 file converter 转换格式失败 报错 Error marking filters as finished,如何解决?
  • ¥15 Arcgis相交分析无法绘制一个或多个图形
  • ¥15 关于#r语言#的问题:差异分析前数据准备,报错Error in data[, sampleName1] : subscript out of bounds请问怎么解决呀以下是全部代码:
  • ¥15 seatunnel-web使用SQL组件时候后台报错,无法找到表格
  • ¥15 fpga自动售货机数码管(相关搜索:数字时钟)