duancuan7057 2013-11-30 16:52
浏览 59

Codeigniter在ajax调用上给出了404错误

I have an upload form which after ajax upload 2 buttons allow the user to change the uploaded photo or delete it. I've implemented the whole system right and works fine. but my problem is and was when I tried to make an ajax call to the function that deletes photos it gave me csrf protection error. after I disabled csrf protection , now it says 404 not found in my response.

PHP://url: "http://localhost/project/index.php/ajax/deleteCarPhoto/"

function deleteCarPhoto()
{
    $src = $this->input->post('src');

    $adPhotos = $this->session->userdata('ad_photos');
    unset($adPhotos[$src]);

    $this->session->set_userdata('ad_photos',$adPhotos);

    echo "<p>Photo deleted</p>";
}

JS:

$("label.btn-danger").on('click',function(e){
    e.preventDefault();
    var selectedElement = this;
    var name = $(this).parents("label").find("input[type=file]").attr('name');
    var src = $(this).parents("label").find("img").attr("src");
    var pattern = /\/([A-Z0-9_-]{1,}\.(?:png|jpg|gif|jpeg))/ig;
    var result = pattern.exec(src)[1];

    $.post({
            url: "http://localhost/project/index.php/ajax/deleteCarPhoto/",
            data: {src : result},
            dataType:'html'
    },function(xhr){
        alert(xhr.responseText);
        $(selectedElement).parents('label').find('.fileinput-preview').css('background',"none");
        $(selectedElement).parents('label').find('.fileinput-preview').css('background',"url('http://localhost/project/assets/images/upload_a_photo.png') no-repeat center center");
        $(selectedElement).parents('label').find('input[type=file]').removeAttr('disabled');
        $("#upload").reset();
    });
});

My HTTP HEADERS:

Accept  */*
Accept-Encoding gzip, deflate
Accept-Language en-US,en;q=0.5
Cache-Control   no-cache
Connection  keep-alive
Content-Length  0
Cookie  ZDEDebuggerPresent=php,phtml,php3; un4vW7pAFT=aNdO76M9erJW9lpHvJtS9SILUiZqb%2FgYGb5Zr9liqlVP3hzLupNYgeWlRAeGOME6mK4xE7ATNdmr%2FVSLdkFsyMX4foVtEzmxOsT%2BX9N9K%2FdqDMTaL0pYlvxloe5zYHYBXHanmSbMhWhPvcZO65HGb29VZsnquPuR%2BVwAnyFsd3R7l0s7TjutaydBdcgUvRUv1n1FkqRZ5oTQ2JfW8RGo7Pye4Lb4VA8OLyzVTgmroVkr%2FA3g24y82EWHAPyv%2B4riDiYmmxVKDWmWdMZ7Ms4sqibYVw4woUyXtNxoWvD6vSphcpw9oPCIsm2guCyf3hJlaIuVvdM0sRvxPf3tz0zvIA%3D%3D
Host    localhost
Pragma  no-cache
Referer http://localhost/project/index.php/advertise/add
User-Agent  Mozilla/5.0 (Windows NT 6.1; rv:25.0) Gecko/20100101 Firefox/25.0
X-Requested-With    XMLHttpRequest
  • 写回答

1条回答 默认 最新

  • dongyupen6269 2013-11-30 17:00
    关注

    If I am a browser, then localhost if my computer. If I am browsing your site http://www.your-web-domain/some/url, then an ajax link to localhost will still refer to my workstation. The link in the script should be http://www.your-web-domain//project/index.php/ajax/deleteCarPhoto/

    评论

报告相同问题?

悬赏问题

  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)