2015-01-08 31 views
0

我在ASP中使用Response.Write通过使用Mandrill API的Javascript发送电子邮件,我已经检查过这段代码至少5次,语法看起来正确我,我不知道为什么这个错误被报告。Javascript代码未终止的字符串常量

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 

我会感谢一些帮助,因为我是初学者。

+0

在黑暗中拍摄刺,但我认为奇引号可能导致该问题(否则会产生一个问题,在未来)。用'''或者''''替换''''''''(逃避不会影响你在ASP中的Response.Write调用)稍微不同的说法,在你的脚本标签是逃避是啊? – Turnerj

+0

您是否将该脚本返回给浏览器执行?如果是这样的话,你真的不希望以这种方式公开你的Mandrill API密钥。 – bvanvugt

回答

1

您必须对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 
%> 
相关问题