javascript - Passing a multiline string as parameter to js function - Stack Overflow

When calling displayBarNotification(stringIPass, 'success', 3500) of nopmerce originally defi

When calling displayBarNotification(stringIPass, 'success', 3500) of nopmerce originally defined in publicmon.js seems the call fails when stringIPass contains newlines. The error on the client-side was something like

Unexpected line break in a string literal

I tried replacing the C# newline character in the ajax function to the js equivalent and it worked. However, I intend to keep the "newlines" for readability reasons. What approach would you suggest?

Pardon me for the lack of the exact error expr. but it's because I'm currently not at work. I will update tomorrow if necessary.

When calling displayBarNotification(stringIPass, 'success', 3500) of nopmerce originally defined in public.mon.js seems the call fails when stringIPass contains newlines. The error on the client-side was something like

Unexpected line break in a string literal

I tried replacing the C# newline character in the ajax function to the js equivalent and it worked. However, I intend to keep the "newlines" for readability reasons. What approach would you suggest?

Pardon me for the lack of the exact error expr. but it's because I'm currently not at work. I will update tomorrow if necessary.

Share Improve this question edited Feb 12, 2020 at 18:09 Trevor 8,0046 gold badges33 silver badges52 bronze badges asked Feb 12, 2020 at 18:04 OnionOnion 311 silver badge7 bronze badges 2
  • developer.mozilla/en-US/docs/Web/JavaScript/Reference/… – Teemu Commented Feb 12, 2020 at 18:06
  • You can use the javascript scape function first – Hackerman Commented Feb 12, 2020 at 18:10
Add a ment  | 

1 Answer 1

Reset to default 6

Official documentation:

Template literals are string literals allowing embedded expressions. You can use multi-line strings and string interpolation features with them.

Use back-ticks ( ` ) to introduce a template literal:

var example = `
  this
  is
  a
  test
`;

console.log(example);

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744680784a4587610.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信