0

I'm using a Response.Write in ASP to send an e-mail via Javascript using the Mandrill API, I've already checked this code for at least 5 times and the syntax looks right to me, I don't know why this error is being reported.

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

I'd appreciate some help since I'm a beginner.

2
  • Taking a stab in the dark but I assume the odd quote marks probably are causing the issue (or will cause an issue in the future). Replace and with either ' or an escaped " (escaped to not interfere with your Response.Write call in ASP). On a slightly different note, I assume though the double " in your script tag are for escaping yeah? Commented Jan 8, 2015 at 12:38
  • Are you returning that script to a browser for execution? If that's the case, you really don't want to be exposing your Mandrill API Key in that manner. Commented Jan 8, 2015 at 17:03

1 Answer 1

1

You have to use the line continuation character _ for multiple lines in the same string in ASP. If you want the output of the response.write formatted, you need to use vbcrlf to output a newline.

I have replaced the in your code with "

<%
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
%>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.