i have to call one C# function from java script.For that i am using ajax post request for calling C# function.But My C# function is not actually called from ajax script.I dont know what is the reason for not calling C# function?
This is my Ajax Code:
<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.6.1.min.js"></script>
<script type="text/javascript">
$(function () {
$("#btnSend").click(function () {
var image = document.getElementById("myCanvas").toDataURL("image/png");
image = image.replace('data:image/png;base64,', '');
$.ajax({
type: 'POST',
url: 'Default.aspx/UploadImage',
data: '{ "imageData" : "' + image + '" }',
contentType: 'application/json; charset=utf-8',
dataType: 'json',
success: function (msg) {
alert('Image sent!');
}
});
});
});
</script>
And this is my C# function :
namespace sample
{
[ScriptService]
public partial class _Default : System.Web.UI.Page
{
[WebMethod()]
public static void UploadImage(string imageData)
{
FileStream fs = new FileStream("D:\\vs-2010projects\\delete_sample\\delete_sample\\myimages\\image.png", FileMode.Create);
BinaryWriter bw = new BinaryWriter(fs);
byte[] data = Convert.FromBase64String(imageData);
bw.Write(data);
bw.Close();
}
}
}