Is that js in a standalone .js file, or in a blade view?
May 23, 2018
6
Level 1
Method Not Allowed exception on ajax file upload
hi , i am quite confused of this error i cant see any error in my code but i get method not allowed error after the lick event of button upload. i am using ajax request to upload an image when i faced this problem. here is my controller code
public function UploadImage(Request $request){
if (Input::hasFile('image'))
{
return "file present";
}
else{
return "file not present";
}
}
here is my route
route::post('AjaxUpload', 'AjaxUploadController@UploadImage')->name('AjaxUpload');
here is my view
<form enctype="multipart/form-data" id="upload_form" role="form" method="POST" action="">
<div class="form-group" >
<button class=" addbtn bg_db control_UPL" title="upload Image">UPL</button>
<input type="hidden" name="_token" value="{{ csrf_token()}}">
<input type="file" id="catagry_logo" name="image" class="form-control-file">
<div class="AjContent">
<img class="looper" src="{{URL::to('admin/images/ajax/looper.gif')}}">
<span class="ajaxData"></span>
</div>
</div>
</form>
here is my Ajax request code
<script type="text/javascript">
document.addEventListener('DOMContentLoaded', function(){
$(".addbtn").click(function(){
$.ajax({
url:"{{route('AjaxUpload')}}",
data:new FormData($("#upload_form")[0]),
dataType:'json',
async:false,
type:'post',
processData: false,
contentType: false,
success:function(response){
console.log(response);
}
});
})
}, false);
</script>
i am getting the error method not allowed on button click event. please some help. thank you.
Level 67
Please or to participate in this conversation.