0

So I'm gettin this error and have no idea why:

jQuery.ajax Uncaught SyntaxError: Unexpected identifier

I am trying to parse some information about a customer to another file that is in the main directory of the FTP-Server called "pricealarm.php"

<script type="text/javascript">
jQuery(document).ready(function() {
    jQuery("#pricealarm-fakeSubmit").click(function(){
      if (jQuery('input[name="pa[offer]"]').val().length > 0 && jQuery('input[name="pa[email]"').val().length > 0 && jQuery('input[name="pa[name]"').val().length > 0 && jQuery('input[name="c_mac"]').val().length > 2 ) {

        //Parsing der Eingegebenen Information in die Datenbank (eigentliches Prozedere in pricealarm.php)
        var parse = {
          currency: jQuery('input[name="pa[currency]"]').val(),
          price: jQuery('input[name="pa[price]"]').val(),
          offer: jQuery('input[name="pa[offer]"]').val(),
          email: jQuery('input[name="pa[email]"]').val(),
          phone: jQuery('input[name="pa[phone]"]').val(),
          name: jQuery('input[name="pa[name]"]').val(),
          product: jQuery('input[name="pa[product]"]').val(),
          variant: jQuery('input[name="pa[variant]"]').val(),
          productID: jQuery('input[name="pa[productID]"]').val(),
          oxArtID: jQuery('input[name="pa[oxArtID]"]').val(),
          shopID: jQuery('input[name="pa[shopID]"]').val() 
        };

        jQuery.ajax(
        {
          type: 'POST',
          url: 'pricealarm.php',
          data: parse,

          success: function() {console.info(parse) },

          error: function() {console.info('pricealarm couldnt parse the data')}
        });
        return false;
    }
    else{
      jQuery('#pricealarm-fakeSubmit')after('<span class="js-oxError_notEmpty">[{ oxmultilang ident="ERROR_MESSAGE_INPUT_NOTALLFIELDS" }]</span>');
    }         
    });
  });
</script>

EDIT: Updated code to fit suggestions. Still not working yet EDIT2: found the error x.x

2
  • are you getting this error in php? in this case - show us that code Commented Mar 10, 2015 at 13:12
  • @k102 no this is a javascript error. Commented Mar 10, 2015 at 13:22

2 Answers 2

2

EDIT: I provided this answer before the entire code sample was posted. Some of it is still relevant.


I think you have incorrectly defined your callback functions. They should be a function object; as they are, they are executing right away. Try:

  jQuery.ajax({
      type: 'POST',
      url: 'pricealarm.php',
      data: parse,
      success: function() {
          console.info(parse);
      },
      error: function() {
          console.info('pricealarm couldn`t parse the data');
      }
  });

Also, make sure you're using a browser that understands console.info. Alternatively -- and this is my personal preference -- use the new jQuery Promise methods for the callbacks:

  jQuery.ajax({
      type: 'POST',
      url: 'pricealarm.php',
      data: parse,
  }).done(function() {
      console.info(parse);
  }).fail(function() {
      console.info('pricealarm couldn`t parse the data');
  });

And lastly, I'm not completely sure about this, but the backtick (`) in the error string might be causing issues. They're part of a templating syntax proposed in ECMAScript 6 that some browsers already support.

Sign up to request clarification or add additional context in comments.

4 Comments

Sorry, it was not intended. It should be there!
Can you provide more context for your code? Show the full method in which it's running, where it exists in your page, etc.
@CORY i found the error. i was missin a . in the else statement
@zeropublix: Great! Also, you are missing a ] in both selectors here jQuery('input[name="pa[email]"').val().length > 0 && jQuery('input[name="pa[name]"').
1

I found the error myself:

 else{
  jQuery('#pricealarm-fakeSubmit')after('<span class="js-oxError_notEmpty">[{ oxmultilang ident="ERROR_MESSAGE_INPUT_NOTALLFIELDS" }]</span>');
} 

was missing a . before after

 else{
  jQuery('#pricealarm-fakeSubmit').after('<span class="js-oxError_notEmpty">[{ oxmultilang ident="ERROR_MESSAGE_INPUT_NOTALLFIELDS" }]</span>');
} 

1 Comment

You're also missing closing brackets in expression in if statement jQuery('input[name="pa[email]"') should be jQuery('input[name="pa[email]"]'). Same for the expressions name and c_mac.

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.