doubei8168
2015-03-04 05:15
浏览 94
已采纳

jquery Uncaught SyntaxError:意外的标记ILLEGAL

With $.post send data to external php

Have following code (modified variable names) text_of_the_ad:"<?php echo htmlspecialchars( substr($arr[0]["SomeText"],0,70), ENT_QUOTES, "UTF-8"); ?>",

text_of_the_ad in external php will get with $_POST['text_of_the_ad']

$arr[0]["SomeText"] is text from mysql column SomeText

In Chrome Console see text_of_the_ad:"CITROEN C4 EXCLUSIVE 2.0 HDI DIESEL 5 DOOR HATCH LOW MILEAGE FSH FULL ",

enter image description here

And see error Uncaught SyntaxError: Unexpected token ILLEGAL

Why the error? May be because word FULL is in the next line and after word FSH there is no ",?

图片转代码服务由CSDN问答提供 功能建议

使用 $ .post 将数据发送到外部php

有以下代码(修改过的变量名) text_of_the_ad:“&lt;?php echo htmlspecialchars(substr($ arr [0] [”SomeText“],0,70),ENT_QUOTES,”UTF-8“) 外部php中的?&gt;“,

text_of_the_ad 将使用 $ _ POST ['text_of_the_ad'] < / p>

$ arr [0] [“SomeText”] 是来自mysql列的文本 SomeText

在Chrome控制台中,请参阅 text_of_the_ad:“CITROEN C4 EXCLUSIVE 2.0 HDI DIESEL 5 DOAT HATCH LOW MILEAGE FSH FULL”,

并查看错误未捕获的SyntaxError:意外的令牌ILLEGAL < / p>

为什么会出错? 可能是因为word FULL 在下一行,而在 FSH 之后没有“,

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • dortmundbvb0624 2015-03-04 05:19
    已采纳

    JavaScript doesn't support multiline strings just like that. The easiest way to hack around this would probably be to just replace a literal with \ before echoing:

    <?php echo str_replace("
    ","\
    ",htmlspecialchars( substr($arr[0]["SomeText"],0,70), ENT_QUOTES, "UTF-8")); ?>
    
    已采纳该答案
    评论
    解决 无用
    打赏 举报
  • dsl2014 2015-03-04 05:23

    You could try using the line continuation character, which is \. So that your source would look like:

    text_of_the_ad:"CITROEN C4 EXCLUSIVE 2.0 HDI DIESEL 5 DOOR HATCH LOW MILEAGE FSH\
    FULL "
    

    Multi-line strings in JavaScript must be escaped, but doing it this way is not going to always produce your desired behaviour - i.e. sometimes browsers might insert newline characters, sometimes they might not.

    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题