mandrill合并标签不接受变量值

时间:2015-04-04 07:55:52

标签: javascript mandrill

请原谅我的第一篇文章!我能够发送"硬编码" global_merge_vars成功使用

 `"autotext": "true",
  "merge": "true",
  "global_merge_vars": [
        {
            "vars": 
                {
                    "name": "LSMESSAGE",
                    "content": "hardcoded"
                }

        }
    ],

  "subject": "*|LSMESSAGE|*",
  "html": "<p> *|LSMESSAGE|* </p>"`

但无法将名为ctlsm的变量传递给&#34;内容&#34;。

"autotext": "true",
  "merge": "true",
  "global_merge_vars": [
        {
            "vars": 
                {
                    "name": "LSMESSAGE",
                    "content": ctlsm
                }

        }
    ],

  "subject": "*|LSMESSAGE|*",
  "html": "<p> *|LSMESSAGE|* </p>"

我只是在我的邮件中获得明星* | LSMESSAGE | *明星。 第一个问题 - 可以在这里使用变量吗? (我确实尝试将ctlsm放在引号中:&#34; ctlsm&#34;) 如果是的话,我做错了什么?该变量在mandrill post之前声明并且有一个值,但似乎在$ ajax部分中失去了它的价值。

// send email using mandrill and API key
      $.ajax({
type: "POST",
url: "https://mandrillapp.com/api/1.0/messages/send.json",
data: { etc etc

2 个答案:

答案 0 :(得分:0)

在javascript中添加+符号到concat字符串

"content": "+ctlsm+"   

这里是带字符串变量的concat示例。

 var text = "hello" 
 document.write(text+" world"); /// this will write hello world

答案 1 :(得分:0)

感谢Nishit。它现在有效。从代码中删除了“var”,将“subject”和“html”代码移到了顶部,并添加了“merge_language”:“mailchimp”,我在mandril网站的代码片段中找到了它。变量名称ctlsm没有引号。无论如何,这就行了。这是有效的代码:

// send email using mandrill and API key$.ajax({
type: "POST",
url: "https://mandrillapp.com/api/1.0/messages/send.json",
data: {
"key": "yourapikeyhere",
"message": {
 "subject": "*|LSMESSAGE|*",
 "html": "<p>  *|LSMESSAGE|* </p>",
 "text": " *|LSMESSAGE|*",
 "from_email": "youremailhere",
  "to": [
      {
        "email": "youremailhere",
        "name": "yournamehere",
        "type": "to"
      },
      {
        "email": "youremailhere",
        "name": "yournamehere",
        "type": "to"
      }
    ],

  "autotext": "true",
  "merge": "true",
  "merge_language": "mailchimp",
  "global_merge_vars": [
        {
           "name": "LSMESSAGE",
            "content": ctlsm

        }
    ]



}

}