javascript - AJAX 未捕获语法错误 : Unexpected token :

标签 javascript jquery html ajax post

我收到以下错误:

Uncaught SyntaxError: Unexpected token :

对于这一行:

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

下面是脚本:

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

最佳答案

您缺少对象括号,因此您的行应该是

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

在脚本中:

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

关于javascript - AJAX 未捕获语法错误 : Unexpected token :,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29779620/

相关文章:

javascript 代码格式化程序和荧光笔

javascript - meteor : to get and show github username and email

javascript - jQuery:防止动画和超时排队?

html - 使用表格的电子邮件发送者问题

html - 当 parent 的 parent 有动画时,为什么我的 iframe 会出错?

javascript - 生成并下载网页截图而不丢失样式

Javascript - 从数组末尾删除空元素的函数式方法

javascript - html中的表单提交触发器

javascript - 如何从相同类名的表数据中获取值并追加

javascript - html 内容中的 css 链接在加载 html 时抛出错误