1

i am making an ajax request in my php file, and the request is returning with correct value. But when I try to use append function in jquery it returns and erro in the console.

$.ajax({
                url:"ajax.php",
                type:"POST",
                success:function(msg){
                    $("#loadMoreButton").hide();
                    alert(msg.length);
                    $.each(msg, function(index){

                        $(".blog-masonry").append("<div class='post-masonry col-md-4 col-sm-6'> <div class='blog-thumb'> <img src='" + msg[index].image +"' alt=""> <div class='overlay-b'> <div class='overlay-inner'> <a href='#' class='fa fa-link'></a> </div></div></div><div class='blog-body'> <div class='box-content'><h3 class='post-title'><a href='" + msg[index].external_link +"' target='_blank'>" + msg[index].title + "</a></h3><span class='blog-meta'>" + msg[index].date_pub + "</span><p>"+ msg[index].Content +"</p></div></div></div>");

                    });
                    $("#loadMoreButton").show();
                },
                dataType:"json",
                data: {"from": ("" + id), "cat" : "<?php echo $_GET['category']; ?>"}
            });

The error says SyntaxError: Expected token ')' in the line where I try to append the html.

I'm not sure what is missing here?

1
  • 2
    Error is self-explanatory, just fix your syntax. Use proper IDE if it's not clear for you where. You have alt="" and it needs to be quoted: alt=\"\". Commented Nov 14, 2015 at 10:05

1 Answer 1

1

Change alt = "" to alt=''

$(".blog-masonry").append("<div class='post-masonry col-md-4 col-sm-6'> <div class='blog-thumb'> <img src='" + msg[index].image +"' alt=''> <div class='overlay-b'> <div class='overlay-inner'> <a href='#' class='fa fa-link'></a> </div></div></div><div class='blog-body'> <div class='box-content'><h3 class='post-title'><a href='" + msg[index].external_link +"' target='_blank'>" + msg[index].title + "</a></h3><span class='blog-meta'>" + msg[index].date_pub + "</span><p>"+ msg[index].Content +"</p></div></div></div>");

Or you can use escape character (as mentioned in the comment)

alt=\"\"

The backslash is used as a marker character to tell the compiler/interpreter that the next character has some special meaning.

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

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.