单击按钮和实际执行的Javascript方法之间会发生什么? [英] What happens between clicking a button and the Javascript method actually executing?

查看:94
本文介绍了单击按钮和实际执行的Javascript方法之间会发生什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用MVC 4,jquery和Telerik的Kendo控件的ASP.NET Web应用程序.

I have an ASP.NET web application using MVC 4, jquery, and Telerik's Kendo controls.

我的网页上有以下内容:

I have the following on my webpage:

<input id="cmdSaveToFile" title="Save To File" class="button" type="button" value="Save To File" onclick="SaveToFile();" tabindex="2" />

但是,如果我在定义了SaveToFile()的Javascript文件中设置了一个断点,则该断点不会被命中.该方法应该将ajax请求发送到服务器,然后服务器将创建一个文件并将其存储在会话变量中,以供以后下载.

However, if I set a breakpoint in my Javascript file where SaveToFile() is defined, the breakpoint does not get hit. This method is supposed to send an ajax request to the server which will then create a file and store it in a session variable for downloading later.

服务器上的错误日志引用了此错误:

Error logs on the server cite this error:

使用JSON JavaScriptSerializer进行序列化或反序列化时出错.字符串的长度超过了在maxJsonLength属性上设置的值.

Error during serialization or deserialization using the JSON JavaScriptSerializer. The length of the string exceeds the value set on the maxJsonLength property.

我已经针对这些特定错误查看了这些问题:

I've looked at these SO questions for that specific error:

在JavaScriptSerializer期间ASP.NET MVC中的MaxJsonLength异常

我是否可以为要在web.config中使用maxJsonLength吗?

我已经将接受的答案的内容添加到我的web.config中,但这不能解决问题.我无法以编程方式设置JsonResult.MaxJsonLength属性,因为我不知道单击按钮和实际执行视图文件中指定的方法之间会发生什么.使用Visual Studio + IE,我在任何地方都无法中断.不在控制器中,也不在JS中.

I've added the accepted answer's contents to my web.config but that did not fix the problem. I cannot programatically set the JsonResult.MaxJsonLength property because I have no idea what is happening between clicking on the button and the method I specified in the view file from actually executing. Using Visual Studio + IE I can't break anywhere; not in the controller and not in the JS.

如果我使用Chrome,则可以在他们的开发工具的事件监听器断点"中按鼠标上/下/单击将其中断,但是执行的所有jquery对我来说都是完全不可读的.可能导致此错误的原因是什么?

If I use Chrome, in their dev tools' "Event Listener Breakpoints" I can get it to break on Mouse Up / Down / Click but all of the jquery that executes is completely unreadable to me. What could it be doing under the hood that would cause this error?

编辑为了明确起见,该网页仅包含一个文本框和2个按钮:保存到文件"和关闭".如果单击保存到文件",则软件会将文本框的内容写入RTF文件,并将该文件呈现给用户以进行下载.他们上传文件并尝试解析后,此文本框包含错误报告.如果我上载并解析了一个小文件,则它的行为正确.只有当我上传非常大的文件时,它会产生大量错误,该错误不再起作用(因为错误报告对于JSON而言太长)...但是,如果我的SaveToFile()中的断点没有被触发,那该怎么办?到底在干嘛?

Edit To clarify, the webpage in question simply contains a textbox and 2 buttons: Save to File, and Close. If you click Save to File, the software writes the contents of the textbox to an RTF file and presents the file to the user for download. This textbox contains an error report after they've uploaded a file and attempted to parse it out. If I upload and parse a small file, it behaves correctly. It's only when I upload very large files which creates a large amount of errors that this no longer works (because the error report is too long for JSON)... But if my breakpoint in SaveToFile() doesn't get triggered then what the hell is it doing?

推荐答案

尝试在您的web.config应用设置中进行设置

try setting this in your web.config app settings

<add key="aspnet:MaxJsonDeserializerMembers" value="2147483644" />

<bindings>
  <basicHttpBinding>
    <binding name="YourBindingName" maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647">
      <readerQuotas maxDepth="20000000" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
      <security mode="Transport"></security>
    </binding>
  </basicHttpBinding>
</bindings>

这篇关于单击按钮和实际执行的Javascript方法之间会发生什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆