I am using summernote, I want to upload image to my web server.. Below is my code which I am using
Default.aspx
<script type="text/javascript">
$(document).ready(function () {
$('#summernote').summernote({
onImageUpload: function (files, editor, $editable) {
alert('image?');
var formData = new FormData();
formData.append("file", files[0]);
$.ajax({
url: "Default.aspx/UploadImage",
data: formData,
type: 'POST',
cache: false,
contentType: false,
processData: false,
success: function (imageUrl) {
alert(imageUrl);
if (!imageUrl) {
// handle error
return;
}
editor.insertImage($editable, imageUrl);
},
error: function () {
alert('error');
// handle error
}
});
console.log('image upload:', files, editor, $editable);
}
});
});
</script>
Default.asp.cs
[System.Web.Services.WebMethod]
public static string UploadImage(HttpPostedFileBase file)
{
//Saving to Server
return imageUrl;
}
But it is not calling server side function. Also, alert(imageUrl) is giving me complete page html.
Where I am wrong?
Updating Question with network information (google chrome)
Edit 2
Updated after suggestion
Code:
url: "About.aspx/UploadImage",
data: "multipart/form-data",
type: 'POST',
cache: false,
contentType: "application/json",
Error:
Note: I have changed Page from Default.aspx to about.aspx (but code is same)
[ScriptService]
? – Kathaleenkatharevusa