JavaScript解析错误 [英] JavaScript parse Error
问题描述
我正在使用laravel 5.1
PHP框架和来自javascript的符号图,但是当我从控制器发送数据时使用'(单引号)但JavaScript解析为一些未定义的值
$data_B_Temp = "{x : new Date('".$piecesTime[$dataLength]."'), y :".$pieces[$dataLength]."}";
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]."}";
此变量将输入图形点
$(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());
});
但是javascript执行为:
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?
推荐答案
根据 Laravel刀片文档,使用{{ }}
会导致转义的字符串,这将导致您看到的行为.
According to the Laravel Blade documentation, using {{ }}
results in an escaped string, which would cause the behavior that you're seeing.
尝试使用{!! !!}
代替;使用该语法将告诉Blade不要转义字符串.
Try using {!! !!}
instead; using that syntax will tell Blade to not escape the string.
...
dataPoints: [{!! $data_B_Temp !!}]
...
这篇关于JavaScript解析错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!