ASP.NET/JavaScript:数组索引溢出:实体框架/LINQ

ASP.NET/JavaScript : Array Index Overflow : Entity Framework/LINQ

本文关键字:实体 LINQ 框架 溢出 数组 NET JavaScript ASP 索引      更新时间:2023-09-26

所以我使用 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之前,所以它把它向前推进,它是导致错误的原因。