mathi mathi - 4 months ago 14
Ajax Question

SyntaxError: unterminated string literal in javascript

I am getting location details from database as a json response and values are coming correctly but my problem is the alignment of content string getting error like unterminated string literal ...

then i am displaying this details in google map info window..

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);


Please help me anyone....

Answer

Just add \ after every line:

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>"; 
Comments