0

I have code like this:

$(function(){ $('.plus').click(function(){ var url = "/accounts/profile/update_thing/" + $(this).parent().attr('id') + "/", $.getJSON(url, function(data){ var items = [] $.each(data, function(key, val) { items.push('<li id="' + key + '">' + val + '</li>'); }); $('<ul/>', { 'class': 'my-new-list', html: items.join('') }).appendTo('body'); }); }) }) 

And Chrome code spectrator saying that i have Uncaught SyntaxError: Unexpected token . in line 4. But I don't know why. Does someone knows what is about?

Ps. Is it normal that I haven't text editor on this site?

2
  • 1
    I suggest commenting out portions of code until you don't see the SyntaxError anymore; its as simple as process of elimination. Commented Jul 13, 2011 at 15:03
  • No, it'is not normal. You can indent your code manually with four spaces at the start of a line. You seem to have managed formatting properly in your previous questions (though please stop writing tags in your titles!) Commented Jul 13, 2011 at 15:03

1 Answer 1

2
var url = "/accounts/profile/update_thing/" + $(this).parent().attr('id') + "/", $.getJSON(url, function(data){ 

...is clearly wrong. Did you mean ; on the first line?

If you indent your code properly then mistakes will be easier to spot.

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

2 Comments

When I remove comma error disappear, but now i just getting "Error in event handler for 'undefined': TypeError: Cannot call method 'replace' of undefined". Could it be because of I don't have DOM elements specified in my jQuery code?
@Cris: This is a separate issue. I don't know what line you're getting that error on, but I do notice that you never check the validity of data. Perhaps you can abstract out the AJAX request and demonstrate the issue in jsfiddle.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.