code_legend
code_legend

Reputation: 3285

AJAX Uncaught SyntaxError: Unexpected token :

I have received the following error:

Uncaught SyntaxError: Unexpected token :

For this line:

data: userCoupon: $('#couponCode').val(),

Below is the script:

$(function() {
  $("#signInButton2").click(function(){
    $.ajax({
      type:'POST',
      url:'coursePayment.php',
      data: userCoupon: $('#couponCode').val(),
      success: function(data){
        alert(data);
      }
    });    
  });    
});

Upvotes: 0

Views: 95

Answers (1)

arcyqwerty
arcyqwerty

Reputation: 10685

You're missing object brackets so your line should be

data: {userCoupon: $('#couponCode').val()},

In the script:

$(function() {
    $("#signInButton2").click(function() {
        $.ajax({
            type: 'POST',
            url: 'coursePayment.php',
            data: {userCoupon: $('#couponCode').val()},
            success: function(data) {
                alert(data);
            }
        });
    });
});

Upvotes: 2

Related Questions