0

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

1 Answer 1

2

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);
            }
        });
    });
});
Sign up to request clarification or add additional context in comments.

9 Comments

For reference, see jQuery's ajax() documentation and examples regarding how to specify a data object.
thanks. that error was correct. one another note, my success seems to be incorrect where i do not want an alert to appear rather just the value to be posted on the other page
I'm not sure I quite understand. If you just want the POST request to happen without an alert, you could just remove the alert line. The request will happen with or without a callback function.
i remove that line but it does not seem to post this is the input <input type="text" oninput="calculate()" name="couponCode" id="couponCode" value="" placeholder="Please Enter Coupon Code" required>
Is the function being called when you click #signInButton2? Can you make a jsfiddle?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.