jQuery.ajax 调用有时不会触发 C# WebMethod
我对网页中的按钮单击事件进行了 jQuery.ajax 调用。此 ajax 调用将大量标记发送回服务器。经过一些处理后,服务器发回一个小 URL 地址。这有时工作得很好,但有时却不行。我在 ajax 调用之前有一个断点,并且在我的 WebMethod 中也有一些断点。看来有时 WebMethod 甚至没有受到攻击。
什么可能导致 .ajax 调用失败?我假设我发送的参数中一定有一些东西。但我正在逃避
标记。
有人有什么想法吗?
$.ajax({
type: 'POST',
url: 'WebServices.asmx/GetBitmapPathForVML',
contentType: 'application/json; charset=utf-8',
data: '{"sVML" : "' + escape($('#divChart')[0].innerHTML) +
'","width" : 800,"height": 600}',
dataType: 'json',
success: function(result) {
var newWindow = window.open ("", "Chart","");
//blah blah
newWindow.document.write("<BODY>");
newWindow.document.write(
'<img src="file" alt="Chart"></img>'.replace('file',result.d)
);
newWindow.document.write("</BODY>");
//blah blah
}
});
I have a jQuery.ajax call on a button click event in my webpage. This ajax call sends quite a lot of markup back to the server. After some processing the server posts back a small URL address. This works fine sometimes but other times doesn't. I have a breakpoint just before the ajax call and also have some in my WebMethod. It appears that sometimes the WebMethod doesn't even get hit.
What could be causing the .ajax call to fail? I'm assuming there must be something in the parameters I am sending. But I am escape
ing the markup.
Anyone got any ideas?
$.ajax({
type: 'POST',
url: 'WebServices.asmx/GetBitmapPathForVML',
contentType: 'application/json; charset=utf-8',
data: '{"sVML" : "' + escape($('#divChart')[0].innerHTML) +
'","width" : 800,"height": 600}',
dataType: 'json',
success: function(result) {
var newWindow = window.open ("", "Chart","");
//blah blah
newWindow.document.write("<BODY>");
newWindow.document.write(
'<img src="file" alt="Chart"></img>'.replace('file',result.d)
);
newWindow.document.write("</BODY>");
//blah blah
}
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我建议您像这样重写您的方法:
I would recommend you rewriting your method like this:
El Ronnoco,
我建议您添加一个错误:回调来检查发生了什么。也许您可以从中获得有用的信息。
El Ronnoco,
I would suggest you to add a error: callback to check what is going on. Maybe you can get usefull information from that.
不喜欢回答我自己的问题(其实我不是)。但问题与最大 JSON 长度属性有关。
我找到了 这里的答案
..并将其添加到我的 webconfig 中...
谢谢所有的答案,尤其是那些关于捕捉错误的答案。
Don't like answering my own question (not that I am, really). But the issue was to do with the maximum JSON length property.
I found the answer here
..and added this to my webconfig...
Thanks for all the answers guys, especially those about catching the errors.