使用Json / jquery将DataURl发送到webservice [英] Send DataURl to webservice using Json/jquery
问题描述
我正在尝试将Base64数据保存到数据库中。
但是我无法将dataUrl发送到我的.asmx文件。
Jquery
Hi,
I am trying to save Base64 data in to database.
But I am not able to send dataUrl to my .asmx file.
Jquery
function UploadUserPhoto() {
var Mycanvas = document.getElementById("tempCanvas");
var dataURL = Mycanvas.toDataURL("image/png");
$.ajax({
url: "LP18WS.asmx/UploadPhoto",
contentType: "application/json; charset=utf-8",
data: {
Base64String: "\'" + dataURL + "\'"
},
dataType: "json",
success: function (msg) {
alert(msg.d);
},
error: function (msg) {
alert(msg + '\n' + xhr.responseText);
},
});
}
Webservice(LP18WS.asmx)
Webservice (LP18WS.asmx)
[WebMethod(EnableSession = true)]
[ScriptMethod(ResponseFormat = ResponseFormat.Json, UseHttpGet = true)]
public string UploadPhoto(string Base64String)
{
string message = "";
//code to save data url in database
return message;
}
但它没有发送dataurl。如果我把一些其他的字符串而不是dataurl它正在工作。
为什么这个数据不能发送?任何人都能指导我吗?
我观察到当dataURL中有大量数据时会发生这种情况。否则,当数据量最小时,它正在工作。你能给我一个解决方案来克服这种情况。
But it is not sending the dataurl. If I put some other string instead of dataurl it is working.
Why this dataurl can''t send?. Can any one guid me?
I have observed that it is happening when there are large amount of data within dataURL. Otherwise when the amount of data is minimum it is working. Can you give me a solution to overcome this situation.
推荐答案
.ajax({
url: LP18WS.asmx / UploadPhoto,
contentType: application / json; charset = utf-8,
data:{
Base64String: \' + dataURL + \'
},
dataType: json,
成功: function (msg){
alert(msg.d);
},
错误: function (msg){
alert(msg + ' \ n' + xhr.responseText);
},
});
}
.ajax({ url: "LP18WS.asmx/UploadPhoto", contentType: "application/json; charset=utf-8", data: { Base64String: "\'" + dataURL + "\'" }, dataType: "json", success: function (msg) { alert(msg.d); }, error: function (msg) { alert(msg + '\n' + xhr.responseText); }, }); }
Webservice(LP18WS.asmx)
Webservice (LP18WS.asmx)
[WebMethod(EnableSession = true)]
[ScriptMethod(ResponseFormat = ResponseFormat.Json, UseHttpGet = true)]
public string UploadPhoto(string Base64String)
{
string message = "";
//code to save data url in database
return message;
}
但它没有发送dataurl。如果我把一些其他的字符串而不是dataurl它正在工作。
为什么这个数据不能发送?任何人都能指导我吗?
我观察到当dataURL中有大量数据时会发生这种情况。否则,当数据量最小时,它正在工作。你能给我一个解决方案来克服这种情况。
But it is not sending the dataurl. If I put some other string instead of dataurl it is working.
Why this dataurl can''t send?. Can any one guid me?
I have observed that it is happening when there are large amount of data within dataURL. Otherwise when the amount of data is minimum it is working. Can you give me a solution to overcome this situation.
这篇关于使用Json / jquery将DataURl发送到webservice的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!