Warm tip: This article is reproduced from serverfault.com, please click

javascript-JQuery.Ajax()不起作用不确定脚本是否正确加载

(javascript - JQuery.Ajax() not working not sure if script is loading properly)

发布于 2020-11-29 03:52:45

我正在尝试使用API​​通过MailChimp发送电子邮件。通过这样做,我可以避免使用任何形式的后端。我不知道我设置的Jquery脚本文件是否错误。

$(document.ready(function () {
  $('#survey').click(function() {
    $.ajax({
        type: “POST”,
        url: “https://mandrillapp.com/api/1.0/messages/send.json”,
        data: {
          ‘key’: ‘api Key’,
          ‘message’: {
            ‘from_email’: ‘email’,
            ‘to’: [
                {
                  ‘email’: ‘email’,
                  ‘name’: ‘RECIPIENT NAME (OPTIONAL)’,
                  ‘type’: ‘to’
                }
              ],
            ‘autotext’: ‘true’,
            ‘subject’: ‘Class Survey’,
            ‘html’: ‘Here is your survey link: <a>link</a>’
          }
        }
       }).done(function(response) {
         console.log(response); 
    });
  });
}); 

这是我在VS Code中收到的所有错误 在此处输入图片说明

我不确定为什么VS Code会突出显示所有代码。我还想提到控制台即使没有提供太多信息也给出了此错误。

Uncaught SyntaxError: Invalid or unexpected token 

谢谢你的帮助!

Questioner
Anon211
Viewed
11
rajesh kakawat 2020-11-29 13:19:34

这是因为你使用了错误的双引号

用这个"代替这个

用这个'代替

    $(document).ready(function() {
        $('#survey').click(function() {
            $.ajax({
                type: "POST",
                url: "https://mandrillapp.com/api/1.0/messages/send.json",
                data: {
                    'key': 'api Key',
                    'message': {
                        'from_email': 'email',
                        'to': [
                            {
                            'email': 'email',
                            'name': 'RECIPIENT NAME (OPTIONAL)',
                            'type': 'to'
                            }
                        ],
                        'autotext': 'true',
                        'subject': 'Class Survey',
                        'html': 'Here is your survey link: <a>link</a>'
                    }
                }
            }).done(function(response) {
                console.log(response); 
            });
        });
    });