问题
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 '
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