Uncaught SyntaxError: Unexpected token } vb.net

2019-07-24 17:45发布

问题:

When I debug my code in Google Chrome, I have a red text saying

Uncaught SyntaxError: Unexpected token }.

I don't understand why and where this is coming from. This is the code from the source console:

var chart = $('#container1').highcharts();chart.series[0].setData(array2);chart.redraw(); });    //]]>
  • Uncaught SyntaxError: Unexpected token }

    </script>
    

Code in vb.net

Dim script As String
    script = _
        "var chart = $('#container1').highcharts();" & _
        '"chart.series[0].setData(array2);" & _
        "chart.redraw();" & _
    " }); "


    ScriptManager.RegisterClientScriptBlock( _
        Me, _
        GetType(Page), _
        "container1", _
        script, _
        True)

i have a Uncaught SyntaxError: Unexpected token }, ub tge vb.net code

updated code:

   Dim script As String
script = _
    "var chart = $('#container1').highcharts();" & _
    "chart.series[0].setData(array2);" & _
    "chart.redraw();" & _
 "}" & _
 ")" & _
 ";"

error:

 var chart = $('#container1').highcharts();chart.series[0].setData(array2);chart.redraw(); });//]]>
Uncaught SyntaxError: Unexpected token }
</script>

回答1:

try:

       Dim script As String
    script = _
        "var chart = $('#container1').highcharts();" & _
        "chart.series[0].setData(array2);" & _
        "chart.redraw();" & _
     "}" & _
     ")" & _
     ";"


回答2:

You can replace " }); " with "".



回答3:

It looks like you have unbalanced curly brackets. Did you copy and paste your script from somewhere?

Try this and let us know if it gets rid of the error:

Dim script As String
script = _
    "var chart = $('#container1').highcharts();" & _
    "chart.series[0].setData(array2);" & _
    "chart.redraw();"