How To Upload File Using Ajax In Codeigniter
I am trying to upload a file along with other parameters using ajax. However, the files are not getting uploaded. Form Code
Solution 2:
<form id="first_form" method="post" enctype="multipart/form-data">
The enctype when file upload.
Solution 3:
-> give id in form tag Submit and add a submit button before form close script to send request $("#save").click(function (event) { event.preventDefault();
// Create an FormData object
var data1 = new FormData($('#fileUploadForm')[0]);
console.log($('#fileUploadForm'));
$.ajax({
type: "POST",
enctype: 'multipart/form-data',
url: "<?php echo base_url(); ?>" + "student/add_data",
data: data1,
processData: false,
contentType: false,
cache: false,
success: function (data) {
data = JSON.parse(data);
console.log(data);
if(data.id==1)
{
localStorage.setItem("user_profile_pic", data.user_pic);
alert("updated sucessfully")
}
}
});
Post a Comment for "How To Upload File Using Ajax In Codeigniter"