开发者

Unexpected syntax error : "\n" in javascript/jquery

The below code is in my javascript/jquery script, but for some reason Firebug tells me I have a "syntax error: var fbbirthday = ;\n".

var fbbirthday = <?php echo $fb_day_of_birth; ?>;
var fbbirthmonth = <?php echo $fb_month_of_birth; ?>;
var selectbirthyear = $('#ad_engine_birth_date_year').val();

Meanwhile, the browser actually shows the following (because the php variables $fb_day_of_birth and $fb_month_of_birth are empty when the user isn't logged into facebook).

var fbbirthday = ;
var fbbirthmonth = ;
var selectbirthyear = $('#ad_engine_birth_date_year').val();

I've spent a while trying to figure out where the \n that firebug finds is coming from. Any h开发者_StackOverflow中文版elp would be appreciated!


This statement is illegal as the right hand side of the assignment is missing:

var fbbirthmonth = ;

This is probably due to $fb_day_of_birth that is an empty string. You should check that and use an alternative value like:

var fbbirthday = <?php echo is_numeric($fb_day_of_birth) ? $fb_day_of_birth : 0; ?>;

Or better use json_encode:

var fbbirthday = <?php echo json_encode($fb_day_of_birth); ?>;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜