我尝试使用 j查询 和 AJAX 将图像保存到服务器,但输入字符串替换当通过流阅读器访问时,所有+符号都带有% 我的 j查询 和 AJAX 致电如下
function saveImage() {
var can = document.getElementById("canvas");
var image = document.getElementById("canvas").toDataURL("image/png");
image = image.replace('data:image/png;base64,', '')
$.ajax({
type: 'POST',
url: 'Default.aspx',
data: { imgData: image },
contentType: 'application/json; charset=utf-8',
dataType: 'json',
}).success(function(response) {
alert('image saved successfully!');
});
}
和c#代码是
if (Request.InputStream.Length >0)
{
string jsonString = String.Empty;
using (var inputStream = new StreamReader(Request.InputStream))
{
jsonString = inputStream.ReadToEnd().ToString();
}
SaveImage(jsonString);