问题描述
我正在尝试使用ajax发布请求上传图像并将其保存在CI4中的控制器中。 但这向我显示了空对象。
这是代码
$.ajax({
url: 'upload',type: 'post',data: {"image":img},// img is the file which is being uploaded.
contentType: false,processData: false,success: function(response){
if(response != 0){
html = '<img src="' + img + '" />';
$("#preview-crop-image").html(html);
alert('file uploaded');
}
else{
alert('file not uploaded');
}
},});
});
控制器代码
public function image_upload()
{
var_dump($this->request->getPost());
}
我正在尝试转储所有对象,但无法弄清楚。 应该在这里添加什么?
解决方法
在网址中添加正斜杠。
url:'/ upload',