3

What does this error mean? "Uncaught SyntaxError: Unexpected identifier"

I get it in this:

 $('#prepare_payment’).attr('disabled','true');
     jQuery('#prepare_payment_form :text').each(function() {
     jQuery(this).attr('disabled', 'true');
 });

And this as well:

$.post(ajaxurl, data, function(response) {

   if(response.indexOf(“Error: “) != -1) {
      $('#paypal_error').css('display', 'block');
      $('#paypal_error').html(response);
      $('#prepare_payment').removeAttr(disabled”);
      jQuery(“#prepare_payment_form :text”).each(function() {
         jQuery(this).removeAttr(“disabled”);
      });
      return false;
   }

Can anyone tell me what the error means and why it's appearing?

3
  • 4
    You are using weird quotes... Commented Mar 4, 2014 at 8:42
  • stackoverflow.com/questions/20725291/… Commented Mar 4, 2014 at 8:43
  • What are these ...“ ” Commented Mar 4, 2014 at 8:45

3 Answers 3

7

You need to change all , or to " or ' in your code, so change:

'#prepare_payment’
“Error: “
disabled”
“#prepare_payment_form :text”
“disabled”

to:

'#prepare_payment'
'Error: '
'disabled'
'#prepare_payment_form :text'
'disabled'

Final code look like:

$.post(ajaxurl, data, function(response) {
   if(response.indexOf('Error: ') != -1) {
      $('#paypal_error').css('display', 'block');
      $('#paypal_error').html(response);
      $('#prepare_payment').removeAttr('disabled');
      jQuery('#prepare_payment_form :text').each(function() {
         jQuery(this).removeAttr('disabled');
      });
      return false;
   }
});
Sign up to request clarification or add additional context in comments.

Comments

1

You are using two types of quotes to delimit the same string. If you look at:

$('#prepare_payment’

you see that you start the string with the ' delimiter and end it with the ` character (which is not a string delimiter). There are two valid string delimiters: ' and ". For each string you can chose which of those two delimiters to use, but you can't mix them.

So, your bug can be fixed using either one of the following two options:

$('#prepare_payment'
$("#prepare_payment"

And in the jQuery(“#prepare_payment_form :text”) statement you are using and characters, which should either be a ' or " character:

jQuery('#prepare_payment_form :text')
jQuery("#prepare_payment_form :text")

Comments

0

The quotes should be ' or " not

  jQuery("#prepare_payment_form :text").each(function() {
     jQuery(this).removeAttr("disabled");
  })

Same for this also, is invalid

$('#prepare_payment')

Also I assume that the $.post() is closed properly

Comments

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.