Dficulty to handle a list with Javascript

Asked

Viewed 98 times

0

I’m having a hard time handling a list by javascript would like a tip or help if possible

that’s the mistake I’m making

Array [ "AC.FIXED" ] registration:280:4
Referenceerror: $ is not defined[Learn More] registration:282:4
Empty string passed to getElementById(). register
Empty string passed to getElementById(). register

and my javascript

<script>
    listaProjeto = "${usuarioBean.listaNomeProjeto}";

    listaProjeto = listaProjeto.replace("[", "")
    listaProjeto = listaProjeto.replace("]", "")
    var teste = listaProjeto.split(",");
    console.log(teste)

    $.each(teste, function(index, value) {
        alert(index + ": " + value);
    });
</script>

from what I read on it says my jQuery isn’t installed, but it’s all right.

  • 1

    Where’s the part where you reference jQuery on the page?

  • 1

    by the code Voce posted the error is not happening in this part, because there is no getElementByID in your code but the error comes from there (and also I think jQuery was not referenced)

  • here is the above code with the jQuery reference <script type="text/javascript" src="/Resources/js/jQuery-2.2.0.min. js"></script> <script> listProject = "${usuarioBean.listaNomeProject}"; listProjeto = listProjeto.replace("[", "") listProjeto = listProjeto.replace("]", ") var test = listProjeto.split(","); console.log(test) $. each(test, Function(index, value) { Alert(index + ": " + value); }); </script>

  • if jquery is installed correctly you may not have referenced it in your HTML for example, something like this <script src="jquery-1.10.1.min.js" type="text/javascript" ></script>

  • because it is expensive more I referenciei it in the normal page

1 answer

1


First, check the ; at the end of the lines.

Following, add the jQuery just above your script and check if the error persists, like this:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<script>
listaProjeto = "${usuarioBean.listaNomeProjeto}";

listaProjeto = listaProjeto.replace("[", ""); // <- Ponto e virgula
  • then put the ; and nothing changed and was already referenced above the code.

  • Let me try to help you then, change your question by displaying exactly where you referenced jQuery and which version you’re using. And for now to leave this behind, below listaProjeto = "${usuarioBean.listaNomeProjeto}"; puts console.log(listaProjeto); to validate the contents of your variable.

Browser other questions tagged

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