Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/385.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript mandrill合并标记不接受变量值_Javascript_Mandrill - Fatal编程技术网

Javascript mandrill合并标记不接受变量值

Javascript mandrill合并标记不接受变量值,javascript,mandrill,Javascript,Mandrill,请原谅我的第一个帖子!我能够使用成功发送“硬编码”全局\u合并\u变量 `"autotext": "true", "merge": "true", "global_merge_vars": [ { "vars": { "name": "LSMESSAGE", "content": "hardcoded"

请原谅我的第一个帖子!我能够使用成功发送“硬编码”全局\u合并\u变量

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

        }
    ],

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

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

"content": "+ctlsm+"   
下面是字符串变量的concat示例

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

谢谢。现在可以了。从代码中删除“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

        }
    ]



}
//使用mandrill和API键$.ajax发送电子邮件({
类型:“POST”,
url:“https://mandrillapp.com/api/1.0/messages/send.json",
数据:{
“密钥”:“yourapikeyhere”,
“信息”:{
“主题”:“*| LSMESSAGE |*”,
“html”:“*| LSMESSAGE |*

”, “文本”:“*| LSMESSAGE |*”, “来自电子邮件”:“youremailhere”, “致”:[ { “电子邮件”:“youremailhere”, “姓名”:“yournamehere”, “类型”:“至” }, { “电子邮件”:“youremailhere”, “姓名”:“yournamehere”, “类型”:“至” } ], “自动图文集”:“真实”, “合并”:“真”, “merge_语言”:“mailchimp”, “全局合并变量”:[ { “名称”:“LSMESSAGE”, “内容”:ctlsm } ] }

}

如果您能描述一下这解决问题的原因,那就太好了。(VLQRQ)这很简单。如果您想在javascript中的任何字符串中使用变量,那么使用+运算符可以在字符串中包含变量
 var text = "hello" 
 document.write(text+" world"); /// this will write hello world
// 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

        }
    ]



}