ASP.NET/JavaScript:数组索引溢出:实体框架/LINQ
ASP.NET/JavaScript : Array Index Overflow : Entity Framework/LINQ
所以我使用 ASP.NET 对后端进行编程,当我将 100 个元素推入数组时,一切正常,但我有 3005 个元素放入数组中,它会变得更大。
responseTwo.Append("ts.push('" + busAddrs[final] + "'); ");
有人知道在 JavaScript 中的数组中拥有未指定索引的方法吗?
编辑:在前端,它是这样的 -
ts.push('ADDRESS LINE HERE'); ts.push('ANOTHER ADDRESS LINE HERE');
等。。。。所以上面的 100 个工作,再多,它停止工作,错误在这里:
https://gyazo.com/d7c05e8b57bb348481cd28597f61261c
&&
Uncaught SyntaxError: Unexpected token ILLEGAL
编辑:由于有些人投票反对,我循环了 100 次然后添加了ts.push('hello');
,无论里面有什么,它仍然返回相同的错误!! -阅读我的评论
编辑:ASP 后端代码:
var response = new StringBuilder();
var responseTwo = new StringBuilder();
while (cnt != tbl.Length)
{
query = busIDs[cnt];
var ttbl = db.tblbus_address.Where(c => c.BusinessID == query).FirstOrDefault();
if(ttbl != null && !string.IsNullOrEmpty(ttbl.Address1))
{
busAddrs.Add(ttbl.Address1.ToString());
} else {
busAddrs.Add("We do not have an address for this...");
}
cnt++;
}
int final = 0;
responseTwo.Append("<script> ts = []; ");
while (final != tbl.Length)
{
response.Append("<li onclick='s(" + final + ");'>" + busNames[final] + "</li>");
responseTwo.Append("ts.push('" + busAddrs[final] + "'); ");
final++;
}
responseTwo.Append(" </script>");
Output.Text = response.ToString();
jsOut.Text = responseTwo.ToString();
BusAddr 是一个数组,BusName 是一个数组,BusIDS 是一个数组。
编辑:https://gyazo.com/f95ece23b28579562a145061797b51a4 - 此图像在开发人员工具中显示没有"令牌"或类似的东西,它只是停止工作......
编辑:数据库中有任何特殊字符没有问题,我搜索了所有内容。
第一个想法
要连接的字符串包含不能位于单个引号内的内容,例如另一个单引号。
因此,在构造字符串之前,必须清除值中的单引号。
像这样:
responseTwo.Append("ts.push('" + busAddrs[final].替换(", "''"(;+ '"'); '");
第二个想法
脚本标签中捏造的 javascript 大致是这样的,在这里的代码段中运行时,它不会产生错误,经过 100 及以上。
我唯一能看到的是,你不会回马车,而我做到了。也许就是这样?
ts = [];
ts.push('hello'); // 1
ts.push('hello'); //
ts.push('hello'); //
ts.push('hello'); //
ts.push('hello'); //
ts.push('hello'); //
ts.push('hello'); //
ts.push('hello'); //
ts.push('hello'); //
ts.push('hello'); // 10
ts.push('hello'); //
ts.push('hello'); //
ts.push('hello'); //
ts.push('hello'); //
ts.push('hello'); //
ts.push('hello'); //
ts.push('hello'); //
ts.push('hello'); //
ts.push('hello'); //
ts.push('hello'); // 20
ts.push('hello'); //
ts.push('hello'); //
ts.push('hello'); //
ts.push('hello'); //
ts.push('hello'); //
ts.push('hello'); //
ts.push('hello'); //
ts.push('hello'); //
ts.push('hello'); //
ts.push('hello'); // 30
ts.push('hello'); //
ts.push('hello'); //
ts.push('hello'); //
ts.push('hello'); //
ts.push('hello'); //
ts.push('hello'); //
ts.push('hello'); //
ts.push('hello'); //
ts.push('hello'); //
ts.push('hello'); // 40
ts.push('hello'); //
ts.push('hello'); //
ts.push('hello'); //
ts.push('hello'); //
ts.push('hello'); //
ts.push('hello'); //
ts.push('hello'); //
ts.push('hello'); //
ts.push('hello'); //
ts.push('hello'); // 50
ts.push('hello'); //
ts.push('hello'); //
ts.push('hello'); //
ts.push('hello'); //
ts.push('hello'); //
ts.push('hello'); //
ts.push('hello'); //
ts.push('hello'); //
ts.push('hello'); //
ts.push('hello'); // 60
ts.push('hello'); //
ts.push('hello'); //
ts.push('hello'); //
ts.push('hello'); //
ts.push('hello'); //
ts.push('hello'); //
ts.push('hello'); //
ts.push('hello'); //
ts.push('hello'); //
ts.push('hello'); // 70
ts.push('hello'); //
ts.push('hello'); //
ts.push('hello'); //
ts.push('hello'); //
ts.push('hello'); //
ts.push('hello'); //
ts.push('hello'); //
ts.push('hello'); //
ts.push('hello'); //
ts.push('hello'); // 80
ts.push('hello'); //
ts.push('hello'); //
ts.push('hello'); //
ts.push('hello'); //
ts.push('hello'); //
ts.push('hello'); //
ts.push('hello'); //
ts.push('hello'); //
ts.push('hello'); //
ts.push('hello'); // 90
ts.push('hello'); //
ts.push('hello'); //
ts.push('hello'); //
ts.push('hello'); //
ts.push('hello'); //
ts.push('hello'); //
ts.push('hello'); //
ts.push('hello'); //
ts.push('hello'); //
ts.push('hello'); // 100
ts.push('hello'); //
ts.push('hello'); //
ts.push('hello'); //
ts.push('hello'); //
ts.push('hello'); //
ts.push('hello'); //
ts.push('hello'); //
ts.push('hello'); //
ts.push('hello'); //
ts.push('hello'); // 110
console.log(ts.length);
第三个想法
你的非法品格busNames[final]
** 调试完每件事后,我注意到数组中确实有一个 ' 导致它搞砸了,但是,我在数组中的 586 处遇到了另一个错误,其中字符串长度对于数组来说太长了,所以值得注意 **
字符串是:水路街 水路街
它导致了错误。
https://gyazo.com/4df8807d84f1561df2b35d4bec670b15
我按字母顺序从"zbr"查询,所以我把它放在zbr
- 在它被T40
之前,所以它把它向前推进,它是导致错误的原因。
- 警报框中的数据通过linq
- 微风得到的是实体而不是对象的集合
- 什么's是相当于LINQ's SelectMany运算符
- 有没有一种方法可以在没有文档或jQuery的情况下使用javascript解码html实体
- Box2D多个实体的一个夹具
- 在MSCRM 2015中使用javascript限制多实体查找
- 使用linq.js按当前日期订购一组momentjs日期
- 有更好的方法吗?(递归解析HTML unicode实体)
- 如何使用angularJS从json的对象数组中显示和计数实体
- 将文档实体传递给JavaScript函数
- fullpage.js和物化.js;使用实体侧导航禁用鼠标滚动
- javascript将html实体条目发布后的下一个字母大写
- 如何转义字符串中的html实体
- Famo.us Js-将实体(粒子)设置到位置的动画
- 使用Angular在HTML中呈现HTML实体字符串
- 如何在Razor中的LINQ表达式中嵌入JavaScript
- 如何获得实体's对象信息
- Symfony 2,在 Javascript 中访问实体对象
- 使用javascript将html实体替换为文本
- ASP.NET/JavaScript:数组索引溢出:实体框架/LINQ