Skip to content
Advertisement

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

I’m trying to use an API to send emails through MailChimp. I can avoid using any sort of back end by doing this. I don’t know if I am setting up my Jquery script file wrong.

$(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); 
    });
  });
}); 

Here are all the errors I am receiving in VS Code enter image description here

I am not sure why VS Code is highlighting all of the code. I also wanted to mention the console is giving this error even though it doesnt give much info.

Uncaught SyntaxError: Invalid or unexpected token 

Thanks for the help!

Advertisement

Answer

it’s because of the wrong double quotes you are using

use this " instead of this

use this ' instead of

    $(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); 
            });
        });
    });
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement