1

I have ajax code like this

$.ajax({
            url: "AJAX_POST_URL",
            type: "POST",
            data: {commentId:commentId,commentText:commentText},
            dataType : 'json'
            success: function(data)
            {
                if(data.error=='false'){
                    $('comment'+commentId).html(commentText);
                }
            },
});

i am facing this error "uncaught syntaxerror unexpected identifier" at url line.

please help

Thanks in advance

1
  • try with absolute path for url than relative Commented Jun 18, 2014 at 5:57

3 Answers 3

2

I just pointed out the syntax error that you made as comment lines

Try,

$.ajax({
    url: "AJAX_POST_URL",
    type: "POST",
    data: {
        commentId: commentId,
        commentText: commentText
    },
    dataType: 'json',  //Missed a comma over here
    success: function (data) {
        if (data.error == 'false') {
            $('comment' + commentId).html(commentText);
        }
    }  //placed an unncessary comma over here
});
Sign up to request clarification or add additional context in comments.

1 Comment

@Srinu glad to help..! and also take care $('comment' + commentId) of this line.. whether you are going to use # or . before comment..!
1

Use '#' before comment selector. Also add ',' before success and remove unnecessary ',' after success.

$.ajax({
      url: "AJAX_POST_URL",
      type: "POST",
      data: {commentId:commentId,commentText:commentText},
      dataType : 'json',
      success: function(data)
      {
       if(data.error=='false'){
          $('#comment'+commentId).html(commentText);
       }
     }
 });

1 Comment

Thank you RGS for your reply.
0

try this

$.ajax({
        url: 'AJAX_POST_URL',
        type: 'POST',
        data: {commentId:commentId,commentText:commentText},
        dataType : 'json'
        }).success(function(data)
        {
            if(data.error=='false'){
                $('comment'+commentId).html(commentText);
            }
        }).error(function () {
              alert("Something went wrong");
          });

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.