gpt4 book ai didi

javascript - Javascript 代码中未终止的字符串常量

转载 作者:行者123 更新时间:2023-12-03 11:06:19 25 4
gpt4 key购买 nike

我正在 ASP 中使用 Response.Write 使用 Mandrill API 通过 Javascript 发送电子邮件,我已经检查过这段代码至少 5 次,语法对我来说看起来很正确,但我不这么认为知道为什么报告此错误。

if err.number = 0 then
Response.Write("<script language=""javascript"" type=""text/javascript"">
$.ajax({
type: “POST”,
url: “https://mandrillapp.com/api/1.0/messages/send.json”,
data: {
‘key’: ‘MYAPIKEY’,
‘message’: {
‘from_email’: ‘MAIL’,
‘to’: [
{
‘email’: ‘MAIL’,
‘name’: ‘ABC’,
‘type’: ‘to’
},
],
‘autotext’: ‘true’,
‘subject’: ‘TEST’,
‘html’: ‘TEST’
}
}
}).done(function(response) {
console.log(response);
});
</script>")
end if

由于我是初学者,因此希望得到一些帮助。

最佳答案

在 ASP 中,您必须对同一字符串中的多行使用行继续符 _。如果您希望 response.write 的输出格式化,则需要使用 vbcrlf 输出换行符。

我已将代码中的 替换为

<%
if err.number = 0 then
Response.Write("<script language=""javascript"" type=""text/javascript"">" & vbcrlf &_
" $.ajax({" & vbcrlf &_
" type: ""POST""," & vbcrlf &_
" url: ""https://mandrillapp.com/api/1.0/messages/send.json""," & vbcrlf &_
" data: { " & vbcrlf &_
" 'key': 'MYAPIKEY'," & vbcrlf &_
" 'message': { " & vbcrlf &_
" 'from_email': 'MAIL',"& vbcrlf &_
" 'to': [" & vbcrlf &_
" {" & vbcrlf &_
" 'email': 'MAIL'," & vbcrlf &_
" 'name': 'ABC'," & vbcrlf &_
" 'type': 'to'" & vbcrlf &_
" }," & vbcrlf &_
" ]," & vbcrlf &_
" 'autotext': 'true', "& vbcrlf &_
" 'subject': 'TEST'," & vbcrlf &_
" 'html': 'TEST'" & vbcrlf &_
" }" & vbcrlf &_
" }" & vbcrlf &_
" }).done(function(response) {" & vbcrlf &_
" console.log(response);" & vbcrlf &_
" });" & vbcrlf &_
" </script>")
end if
%>

关于javascript - Javascript 代码中未终止的字符串常量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27840074/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com