最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin0浏览0评论

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

发布评论

评论列表(0)

  1. 暂无评论