PRB - MVC-vs-XMLHttpRequest.responseText截断... [英] PRB - MVC-vs-XMLHttpRequest.responseText truncated...

查看:61
本文介绍了PRB - MVC-vs-XMLHttpRequest.responseText截断...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请帮助,当我尝试从带有MVC应用程序的javascript使用XMLHttpRequest时,我有大约127821个字符的文本限制。


我还没有插入IP-像Fiddler这样的跟踪工具,为了验证这一点,但我不排除MVC应用程序截断文本的可能性。


重现步骤:

1)制作一个MVC网络应用程序。

2)来自"索引" view构建一个非常大的字符串并将其从Index控制器返回为"this.Content(csMyVeryLargeString);"

  随意添加任何mime类型,如"text / plain";或者"text / xml",没关系。

3)从javascript调用此代码:


var objXML = new XMLHttpRequest();

objXML.open(" POST"," URL-TO-ABOVE-CONTROLLER-FROM-STEP-2",false); //注意false使得这个SYNCHRONOUS ...

objXML.setRequestHeader(" Content-Type"," application / x-www-form-urlencoded");

var csParameters =" test = test" ;; //随意尝试其他参数...

objXML.setRequestHeader(" Content-length",csParameters.length);

objXML.send(csParameters);


    if(objXML.status == 200)

    {

      var iLen = objXML.responseText.length; //错误!字符串被截断大约127821个字符!!!

    }


解决方案

我发现了这个问题的原因。


这很复杂。正在使用的浏览器是IE9。毕竟,responseText并没有被截断。 IE9调试器(按F12)不显示所有文本。我使用手表标签基本确认文本全部都是这样检索的: 
objXML.responseText.substr(127000,821); 从这开始,我最终在调试器中确认,调试器正在截断调试符号,数据实际上很好。


发现这是非常痛苦的。


Please help, I am having a text limitation of about 127821 characters when trying to use XMLHttpRequest from javascript with a MVC app.

I have not plugged in a IP-Trace tool like Fiddler yet, to verify this, but I do not rule out the possibility that the MVC app is truncating the text.

Steps to reproduce:
1) Make a MVC web app.
2) From the "Index" view build a very large string and return it from the Index controller as "this.Content(csMyVeryLargeString);"
   Feel free to add any mime type like "text/plain" or "text/xml", it does not matter.
3) From javascript call this code:

var objXML = new XMLHttpRequest();
objXML.open("POST", "URL-TO-ABOVE-CONTROLLER-FROM-STEP-2", false); // Note the false makes this SYNCHRONOUS...
objXML.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
var csParameters = "test=test"; // Feel free to try other parameters...
objXML.setRequestHeader("Content-length", csParameters.length);
objXML.send(csParameters);

    if (objXML.status == 200)
    {
      var iLen = objXML.responseText.length; // ERROR! String is truncated at about 127821 characters!!!
    }

解决方案

I have discovered the cause of this problem.

It is very complicated. The browser being used was IE9. And the responseText is not being truncated after all. The IE9 debugger (press F12), does not show all of the text. I used the watch tab to basically confirm the text was all retrieved as such:  objXML.responseText.substr(127000, 821);  From this, I coudl finally confirm in the debugger, it was the debugger that was truncating the debug symbols, and the data was in fact fine.

This was very painful to discover.


这篇关于PRB - MVC-vs-XMLHttpRequest.responseText截断...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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