Nik
Nik

Reputation: 123

Unexpected token ILLEGAL ajax post

I am getting the below error in the console log:

"Uncaught SyntaxError: Unexpected token ILLEGAL" on 7 line (url: ...). 

If I comment line 7, I get this:

"Uncaught SyntaxError: Unexpected token ILLEGAL" on 8 line.

I am using jquery-2.1.0.

Here is my code:

var main = function(){
   $('.btn').click(function(){
      var sumCalc = $('#fieldname4_1').text();
      var phone = $('#fieldname18_1').text();
      var adminEmail = "[email protected]";

      $.ajax({
         url: “https://mandrillapp.com/api/1.0/messages/send.json”,
         type: “POST”,
         data: {
           ‘key’: ‘some key here’,
           ‘message’: {
             ‘from_email’: ‘some mail’,
             ‘to’: [{
                ‘email’: adminEmail,
                ‘name’: ‘admin’,
                ‘type’: ‘to’
              }],
             ‘autotext’: ‘true’,
             ‘subject’: ‘subj’,
             ‘html’: ‘<h1>hello</h1>
                <p>dats phone: </p>’ + phone
            }
         }
      })
      .done(function(response) {
             console.log(response); // if you're into that sorta thing
      });
   });
 }

$(document).ready(main);

Upvotes: 1

Views: 872

Answers (3)

Kevin Ji
Kevin Ji

Reputation: 10489

You are using curly quotes instead of straight quotes, which JavaScript does not support. Just do a search and replace to replace all curly quotes (, , , ) with straight quotes (", ').

Upvotes: 1

maerics
maerics

Reputation: 156424

Just guessing here, but it looks like your editor is inserting some "fancy quotation marks" (“”‘’) instead of the regular ones ("').

Upvotes: 1

Quentin
Quentin

Reputation: 943214

JavaScript strings cannot be quoted with (LEFT SINGLE QUOTATION MARK ) and (RIGHT SINGLE QUOTATION MARK) characters. Use ' (APOSTROPHE) or " (QUOTATION MARK).

Upvotes: 2

Related Questions