SyntaxError:javascript中未终止的字符串文字

时间:2016-07-22 14:04:57

标签: javascript php ajax

我从数据库获取位置详细信息作为json响应并且值正确,但我的问题是内容字符串的对齐得到错误,如未终止​​的字符串文字......

然后我在谷歌地图信息窗口中显示这些细节..

 var contentString = "<div><h4>Start Location : "+ locations[i].start_loc + "</h4>
                           <h4> Driver Name : "+ locations[i].driver_name + "</h4>
                           <h4> Driver Mob No : "+ locations[i].mob_num + "</h4>
                           <h4> Passenger Name : "+locations[i].passenger_name + "</h4>
                           <h4> Passenger Mob No : "+locations[i].mob_no + "</h4>
                           <h4> Cab Reg No : "+ locations[i].cab_reg_no + "</h4></div>"; 

                    infowindow.setContent(start_contentString);
                    infowindow.open(start_map, start_marker);

请帮助我......

2 个答案:

答案 0 :(得分:2)

只需在每行后添加\

var contentString = "<div><h4>Start Location : "+ test + "</h4> \
                           <h4> Driver Name : "+ locations[i].driver_name + "</h4> \
                           <h4> Driver Mob No : "+ locations[i].mob_num + "</h4> \
                           <h4> Passenger Name : "+locations[i].passenger_name + "</h4> \
                           <h4> Passenger Mob No : "+locations[i].mob_no + "</h4> \
                           <h4> Cab Reg No : "+ locations[i].cab_reg_no + "</h4></div>"; 

答案 1 :(得分:0)

回答只是为了显示备用多行...

var contentString = "<div><h4>Start Location : "+ test + "</h4>" + 
                       "<h4> Driver Name : "+ locations[i].driver_name + "</h4>" +
                       "<h4> Driver Mob No : "+ locations[i].mob_num + "</h4>" +
                       "<h4> Passenger Name : "+locations[i].passenger_name + "</h4>" +
                       "<h4> Passenger Mob No : "+locations[i].mob_no + "</h4>" +
                       "<h4> Cab Reg No : "+ locations[i].cab_reg_no + "</h4></div>";