我在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
因为我是初学者,所以我很感激。
答案 0 :(得分: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
%>