afridy
April 13, 2015, 6:46am
1
Hi folks,
i am sending the below strings to a js tool tip. but i am getting the error :
SyntaxError: unterminated string literal{title: ‘#33 test…’,start: ‘2015-04-15’,tip: 'Order ID : 33
<?php
//compose a tool tip//
$tip="Order ID : " . $order_id . "\n" .
"Client Name :" . $client_id . "\n" .
"Order Description :" . $order_description . "\n" .
"Assign To :" . $assign_to . "\n" .
"Order Date :" . $order_date . "\n" .
"Deadline :" . $dead_line . "\n";
"Days Remaining :" . $days_remaining;
?>
you have used semi colon( instead of concatenation operation(.)
afridy
April 13, 2015, 7:08am
4
Hi pbsonawane,
thanks for correcting that mistake. but its not the real problem. now i have further shorten the code.
//compose a tool tip//
$tip="Order ID : " . $order_id . "\n";
but problem remains same. the error points to the \n charactor only. if i remove the \n and it works. but i need line brakes.
which should be preceded by a comma in order for the generated JavaScript to be valid.
afridy
April 13, 2015, 7:21am
6
Did not get you Felgall.
somthing like
$tip="Order ID : " . $order_id . ",\n";
The “unterminated string literal” makes me think it’s a JSON syntax error. i.e.
'Order ID : 33
should have a quote after “ID”
Though I have a feeling another error is soon to follow due to the “double semi-colons”
,tip: 'Order ID : 33
afridy
April 13, 2015, 8:53am
9
Did not get you Felgall.
somthing like
$tip="Order ID : " . $order_id . ",\n";
Hi buddy, no, json is not used.
Let’s go back to your error message.
The problem is that the string Order has not been closed, and a comma needs to separate it from the next ID part.
What you are wanting to end up with for that object is:
{title: ‘#33 test’, start: ‘2015-04-15’, tip: ‘Order’, ID: 33}
If you really want to avoid confusion, you may want to end up with the following:
{
"title": "#33 test",
"start": "2015-04-15",
"tip": "Order",
"ID": 33
}
afridy
April 13, 2015, 10:42am
11
Paul_Wilkins:
The problem is that the string Order has not been closed, and a comma needs to separate it from the next ID part.
What you are wanting to end up with for that object is:
{title: ‘#33 test’, start: ‘2015-04-15’, tip: ‘Order’, ID: 33}
If you really want to avoid confusion, you may want to end up with the following:
Hi paul,
so what about the new line \n? coz i wanted to show those items line by line.
Yes, new lines are perfectly fine too.
Given the recent changes, what code do you currently have? And what further help do you want with it?
1 Like
afridy
April 13, 2015, 11:05am
14
Hi guys,
nop nop, i think u did not understand my problem. this is my problem.
<?php
$tip="Order ID : " . $order_id . " / " .
"Order Date :" . $order_date . " / " .
"Deadline :" . $dead_line ;
?>
This works well with the java script calender tool tip
<?php
$tip="Order ID : " . $order_id . "\n" .
"Order Date :" . $order_date . "\n" .
"Deadline :" . $dead_line;
?>
This does not work. error
The JSON spec doesn’t allow newlines, or any control character for that matter, within strings. Instead, you’ll have to send a backslash-n.
$tip="Order ID : " . $order_id . "\\n" .
"Order Date :" . $order_date . "\\n" .
"Deadline :" . $dead_line;
1 Like
In the attempt to remain on track, OP said it’s not being used as JSON code in post #9 .
1 Like
Well it certainly isn’t a PHP error because the error shows up in the browser console. So the error happens on the frontend on code that looks and behaves conspicuously like JSON.
1 Like
afridy
April 14, 2015, 6:15am
18
Worked !!!
//compose a tool tip//
$tip="Order ID : " . $order_id . "\\n" .
"Customer Name :" . get_customer_name($customer_id,$db) . "\\n" .
"Order Description :" . $row['order_desc'] . "\\n" .
"Assign To :" . get_sewer($assign_to,$db) . "\\n" .
"Order Date :" . $order_date . "\\n" .
"Deadline :" . $dead_line . "\\n" .
"Days Remaining :" . $days_remaining;
THANK YOU GUYS FOR YOUR VALUABLE TIME!!!
1 Like
afridy
April 14, 2015, 6:19am
19
Sorry, did not notice ur suggession. just eventually spotted.any way problem had solved. thanks buddy.
system
Closed
July 14, 2015, 1:23pm
20
This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.