jQuery giving "Unexpected token ;" problem in variable assignment

Asked

Viewed 43 times

0

I use this code below to load in the display of a Datatable values according to what the user selects, it is not possible to use the Datatable standard and it needs to be so so that I can request the necessary amount from the server. The code below is how it is done

1 if ( $("#ITENSPAGINA").change() ){
2     var valor = $("#ITENSPAGINA").val();
3
4     $('#TABELACTRECEBER').DataTable({
5             "pageLength": valor;    // informa ao DataTable a quantidade que deve ser exibida na tabela
6         }
7     );
8 }

This way it is, it works as expected, but I have another problem that part of this algorithm (line 5)

Erro do console Linha do erro obtida no console (ignore the line number) Linha do erro obtida no console 2

And as is with this error presented in the first image, no Javascript algorithm works after that, for all I get the same kind of error: Erro de JavaScript que parte do jQuery

Now if I simply remove the ";" (line 5)

1 if ( $("#ITENSPAGINA").change() ){
2     var valor = $("#ITENSPAGINA").val();
3
4     $('#TABELACTRECEBER').DataTable({
5             "pageLength": valor
6         }
7     );
8 }

The above jQuery code stops working but all other page Javascripts start working again.

I need this jQuery code working this way so I have my table working correctly and together need the page Javascripts working. In other words, they all have to work. What I need is just to be able to use the variable without the ";" inside jQuery but still work the same way.

Although the title seems to be a duplicate question, I did not find any question with this type of problem, not "Unexpected token ;" but rather of a ; problem within a jQuery by using an indispensable variable.

  • You are calling some variable or function in your code called "search"?

  • Yes, "search" is just an example, but if I remove the quoted ";" it works like any other that also doesn’t work if I leave the ";"...

  • Checks which value is being stored in its value variable. You can use the console.log for this

  • I can tell you for sure ; shouldn’t be there, now, because the jQuery code isn’t working I haven’t been able to identify yet.

  • The variable appropriately passes the value of "ITENSPAGINA" (Combobox), there has predefined 10/25/50/100 to select, and it is passing the values as it should. What you would solve would be to use the variable without the ; but jQuery does not identify it that way

  • "pageLength": value; sub-stitua that ; by , comma

  • In this way (exchange ";" for ",") the page does not load the information, it is as if it does not change the "value"

  • The error returned by the console is that "search" is not set. What part of your code are you using it in? Understand that in the loading order of your page, scripts prior to the identified error are normally loaded. Try removing the scope containing "search"

  • As I said above, searching is only one example that gives problem when I use the ;

Show 4 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.