JavaScript parse Error

百般思念 提交于 2019-12-13 23:40:23

问题


I am using laravel 5.1 PHP framework and a sign chart from a javascript, But when i send data from controller with ' (single quote) but JavaScript Parse as some undefined value $data_B_Temp = "{x : new Date('".$piecesTime[$dataLength]."'), y :".$pieces[$dataLength]."}";

this variable will make a graph point input as

$(function () {

var chart = new CanvasJS.Chart("TempChart",
{


  axisX:{
    title: "time",
    gridThickness: 2,
    interval:1,
    intervalType: "hour",
    valueFormatString: "hh TT K",
    labelAngle: -10
  },
  axisY:{
    title: "distance"
  },
  data: [
  {
    type: "line",
   dataPoints:[{{$data_B_Temp }}]

  }
  ]
});

$("#TempChart").CanvasJSChart(chart.render());


});

But the javascript executes as :

dataPoints:[{x : new Date('2015-10-30 18:16:08'), y :38.5}]

I'm confused &#039 is coming? how to solve it?


回答1:


According to the Laravel Blade documentation, using {{ }} results in an escaped string, which would cause the behavior that you're seeing.

Try using {!! !!} instead; using that syntax will tell Blade to not escape the string.

...
dataPoints: [{!! $data_B_Temp !!}]
...


来源:https://stackoverflow.com/questions/33441211/javascript-parse-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!