简体   繁体   中英

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM