-1

So I am using ASP.NET to program the back end, it all works fine when I push 100 elements into an array but I have 3005 elements to put into the array and it will get bigger than that.

responseTwo.Append("ts.push('" + busAddrs[final] + "'); ");

anyone know a way to have unlimated index's in an array in JavaScript?

Edit: in the front end, it comes out like this -

ts.push('ADDRESS LINE HERE'); ts.push('ANOTHER ADDRESS LINE HERE');

ect.... so 100 of the above works, any more and it stops working and the error is here:

https://gyazo.com/d7c05e8b57bb348481cd28597f61261c

&&

Uncaught SyntaxError: Unexpected token ILLEGAL

EDIT: since SOME are voting down, I looped 100 times then added ts.push('hello'); and it still returns the same error no matter whats inside it!!! - read my comments

Edit: ASP backend code:

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 is an array, BusName is an array, BusIDS is an array.

EDIT: https://gyazo.com/f95ece23b28579562a145061797b51a4 - this image shows in developer tools that there is no 'token' or anything of such, it just stops working...

EDIT: There is NO issues with having any special characters in the database, I searched for everything.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Jaquarh
  • 6,493
  • 7
  • 34
  • 86
  • 1
    maximum array size in javascript http://stackoverflow.com/questions/6154989/maximum-size-of-an-array-in-javascript .you should escape the string you used to create `ts.push(...)` : `Uncaught SyntaxError: Unexpected token ILLEGAL` it might contain `'` – Hacketo Feb 12 '16 at 15:32
  • That is more than 100 according to that, please look at the error and the image to understand because I don't think its the index that's the issue. @Hacketo – Jaquarh Feb 12 '16 at 15:33
  • I just pushed 4000 elements to a test array in my console, and it worked instantly without any issues. I do not think your issue is with the size of the array, I think it's what you're pushing to it. – sg.cc Feb 12 '16 at 15:33
  • it looks like your code is bad. – Daniel A. White Feb 12 '16 at 15:33
  • Thats the 101st thing that comes up as an error, i try skip it and it stills errors no matter what I am trying to push into it – Jaquarh Feb 12 '16 at 15:34
  • Why are you trying to build JS on the back-end? Why not send some JSON to the client and then build the array? – Andy Feb 12 '16 at 15:35
  • Because I am using ASP.NET and Entity Framework to work with Databases, the front end idea was just a simple onclick of the Business ID which changes a output innerHTML to the Address corresponding to that Business name.. @Andy – Jaquarh Feb 12 '16 at 15:37
  • I did not downvote this question, btw – toddmo Feb 12 '16 at 15:38
  • What type is responseTwo and how is it created? – Kevin Collins Feb 12 '16 at 15:40
  • Ill edit the quesiton and put my ASP code in for you then @Kevin Collins – Jaquarh Feb 12 '16 at 15:40
  • 1
    I suspect there's a string value with some sort of non-printable character that causes the syntax error in Javascript. – Kevin Collins Feb 12 '16 at 15:46
  • I first thought that, but I get the same error no matter what the 101st value is @Kevin Collins – Jaquarh Feb 12 '16 at 15:47

2 Answers2

0

FIRST THOUGHT

The string you are concatenating contains something that cannot be inside a single quote, like another single quote.

So you must clean out single quotes in the values before you construct your string.

Something like:

responseTwo.Append("ts.push('" + busAddrs[final].Replace("'", "\'"); + "'); ");

SECOND THOUGHT

The fabricated javascript inside your script tag is approximately like this and it causes no errors when running in the snippet here, going through 100 and beyond.

The only thing I can see is that you are not going carriage returns and I did. Maybe that's it?

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);

THIRD THOUGHT

Your illegal character is in busNames[final]

toddmo
  • 20,682
  • 14
  • 97
  • 107
  • Not true, I looped 100 times then added something like: hello and it still came up with the same error. Its always the 101st string that error's - see the image, there is no single quote in the string – Jaquarh Feb 12 '16 at 15:35
  • @KyleE4K, please add your full code to the question, and if you can, use the snippet feature. I'd like to play with it. I'm bored ;) – toddmo Feb 12 '16 at 15:40
  • It is in ASP, not Javascript @toddmo However, my issue is with the JavaScript – Jaquarh Feb 12 '16 at 15:43
  • .replace is not even something in ASP in that aspect @toddmo haha but thanks – Jaquarh Feb 12 '16 at 15:46
  • your code isn't worth anything to me, please see the edited post. @toddmo – Jaquarh Feb 12 '16 at 15:52
  • It's just dummy code but it works with no error, so maybe it's my carriage return that's making it work? – toddmo Feb 12 '16 at 15:53
  • I am not programming in Javascript, I am simply pushing an array from ASP into JavaScript so each address gets pushed from the ASP array into the Javascript array. The issue is with the Javascript where the image shows: for some reason, the 101st element getting pushed into the array: no matter what string it is, returns the error shown. It is pushed from ASP to Javascript the SAME way everytime (While loop) so why does it mess up at the 101st? @toddmo – Jaquarh Feb 12 '16 at 15:58
  • @KyleE4K the string where it starts to fail (from the screen shot) is '22 BALTA CRESCENT' ... could you copy/paste that string into Notepad++ and then View->Show Symbol->Show All Characters – Kevin Collins Feb 12 '16 at 16:14
  • See my answer for the reason but its a weird one because I didn't know that you could not have a long string... @Kevin Collins – Jaquarh Feb 12 '16 at 16:28
-1

** After debugging each thing, I noticed that I did have a ' in the array which caused it to mess up however, I encountered another error at 586 in the array where the string length was too long for the array so thats worth noting down **

the string was: WATERWAY STREET WATERWAY STREET

It caused the error.

https://gyazo.com/4df8807d84f1561df2b35d4bec670b15

I was querying from 'zbr' alphabetically so I put it as zbr - before it was T40 so it brought it forwards and it was the one causing the errors.

Jaquarh
  • 6,493
  • 7
  • 34
  • 86
  • If it was an apostrophe, I'd appreciate you marking my answer as the answer. Even if it wasn't the main problem, it was one of the problems. – toddmo Feb 12 '16 at 17:07
  • the apostrophe wasn't the cause of the issue, It was the string. After I fixed that issue, then I got the error because of the apostrophe. The issue I had wasn't anything to do with symbols. – Jaquarh Feb 15 '16 at 08:42