[英]Codeigniter gives 404 error on ajax call
我有一个上传表格,在ajax上传后2个按钮允许用户更改上传的照片或删除它。 我已经实现了整个系统并且工作正常。 但我的问题是,当我试图对删除照片的函数进行ajax调用时,它给了我csrf protection error
。 在我禁用csrf protection
,现在它说我的回复中404 not found
。
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();
});
});
我的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
如果我是浏览器,那么localhost如果我的电脑。 如果我正在浏览您的网站http://www.your-web-domain/some/url ,那么到localhost的ajax链接仍然会引用我的工作站。 脚本中的链接应该是http://www.your-web-domain//project/index.php/ajax/deleteCarPhoto/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.