Uncaught SyntaxError: Unexpected identifier

Hi, I am getting a JS error:

Uncaught SyntaxError: Unexpected identifier 

here

 <script type="text/javascript"> var cur_level = 1; var ids_arr = new Array(<?php echo $max_level?>); var im_here = new Array(<?php echo $max_level?>); ids_arr[0] = 1; im_here[0] = "|"; function displayData(id, level, used, title) { if(used){ choice = document.getElementById('divv'+id).innerHTML; document.getElementById('test_div').innerHTML = choice; } else { document.getElementById('test_div').innerHTML = ' No lerning paths to show.'; updateLinksDiv(id, level, title); } } function updateLinksDiv(id, level, title) { var links_div_info = document.getElementById('links_parent_'+id); var tmpHTML = ''; var here = ''; for(i=0;i<level;i++){ here+= '->'+im_here[i]; links_div_info = document.getElementById('links_parent_'+ids_arr[i]); tmpHTML += '<div id="divl_'+links_div_info.id+'">'+links_div_info.innerHTML+'</div>'; } links_div_info = document.getElementById('links_parent_'+id); tmpHTML += '<div id="divl_'+links_div_info.id+'">'+links_div_info.innerHTML+'</div>'; document.getElementById('links').innerHTML = tmpHTML; ids_arr[i] = id; im_here[i] = title; } </script> <script type="text/javascript"> window.onload=updateLinksDiv(1 , 0 , "|" ) ; </script> 

The functions involve creating an โ€œextensionโ€ that opens with levels, and everything works fine until I add a โ€œheaderโ€ and I started getting an error. the error points me to the last and I just can't find the error ... I'm trying to call displayData like this

 onclick="displayData('.$cat->id.','.$cat->level.',0,'.$cat->title.')" 

any suggestions that I do not see.

Thank you

+6
source share
1 answer

In your comment, you say that displayData(26,1,0,ื›ื™ืชื” ื’) generated displayData(26,1,0,ื›ื™ืชื” ื’) . This explains the symptoms, since here the last parameter contains a space in addition to the Hebrew letters, so embedded JavaScript treats it as two identifiers separated by a space, and the identifiers are probably undefined. Google Chrome provides an error message that you describe, while Firefox and IE speak more mysteriously, "missing" after a list of arguments. "

Obviously, the generated code must have the last parameter in quotation marks, i.e. 'ื›ื™ืชื” ื’'. You need to change the generation to hide them.

+8
source

Source: https://habr.com/ru/post/905447/


All Articles