【发布时间】:2014-04-28 12:17:25
【问题描述】:
我正在尝试将 html2canvas 图像保存到 asp.net webmethod 中的服务器端代码。为此,我试图通过 jquery ajax click 方法发送参数。客户端代码上的一切都很好,因为我没有得到任何类型错误或警告,但同时我也没有在服务器端获取图像。我试图从很长时间内找出问题,但没有找到方法或发生它的原因。这是我的客户端代码..
$("#excel").on("click", function (e) {
e.preventDefault();
html2canvas($("#placeholder").get(0), {
onrendered: function (canvas) {
var img = canvas.toDataURL().replace(/^data[:]image\/(png|jpg|jpeg)[;]base64,/i, "");
$.ajax({
type: "POST",
url: "Default.aspx/MyMethod",
data: "img=" + img,
success: function (msg) {
alert("Data Saved: " + msg);
}
});
}
});
});
请大家帮帮我。我完全被这种情况震惊了。 需要救生员。 提前致谢。
这是我的服务器端代码..
[WebMethod]
public static void MyMethod(string img)
{
string fileNameWitPath = "D:/Kabir/custom_name.png";
using (FileStream fs = new FileStream(fileNameWitPath, FileMode.Create))
{
using (BinaryWriter bw = new BinaryWriter(fs))
{
byte[] data = Convert.FromBase64String(img);//convert from base64
bw.Write(data);
bw.Close();
}
}
}
这是我的网络服务代码..
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
// [System.Web.Script.Services.ScriptService]
public class WebService : System.Web.Services.WebService {
[WebMethod]
public static void MyMethod(string img)
{
string path = HttpContext.Current.Server.MapPath("/") + "Test.jpg";
//string fileNameWitPath = "D:\\Kabir\\custom_name.png";
using (FileStream fs = new FileStream(path, FileMode.Create))
{
using (BinaryWriter bw = new BinaryWriter(fs))
{
byte[] data = Convert.FromBase64String(img);//convert from base64
bw.Write(data);
bw.Close();
}
}
}
}
这在萤火虫中给出了这个错误..
System.InvalidOperationException: MyMethod Web Service method name is not valid.
at System.Web.Services.Protocols.HttpServerProtocol.Initialize()
at System.Web.Services.Protocols.ServerProtocolFactory.Create(Type type, HttpContext context, HttpRequest request, HttpResponse response, Boolean& abortProcessing)
为什么会出现这个错误?
【问题讨论】:
-
这里没有足够的信息来回答您的问题。我不知道您的 ajax 调用在做什么或任何变量。也许查看您正在使用的产品的常见问题解答? html2canvas.hertzen.com/faq.html
-
@onskee 你想要什么信息?需要看我的服务器端代码吗?
-
如果您希望生成服务器端图像,服务器端代码可能会有所帮助。
-
@onskee 我用服务器端代码更新了我的帖子。请参阅
-
@onskee 请帮我解决这个问题先生,我已经尝试了一切,但无法解决它..
标签: javascript jquery html asp.net ajax