Illegal character in Jquery near OnClick function

972 Views Asked by At

I've below a script-

<head>
   <script 

src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
</head>


<script type="text/javascript">

    $(document).ready(function () {
        $('.error-load').hide();
        $('#imgLoading').hide();


        $("#BtnLoadMore").click(function () {
            $(this).hide();
            var lastArticleId = $('#hdnLastArticle').val();
            var sortOrder = $('#<%= hdnSortValue.ClientID  %>').val();
alert(sortOrder);
            $('#imgLoading').show();
            $.ajax({
                type: "POST",
                contentType: "application/json; charset=utf-8",
                data: '{"RowId":"' + lastArticleId + '", "SortOrder":"' +sortOrder + '"}',
                url: "http://blogs-test.com/themes/blogs/vitalvotes/LoadService.aspx/GetNextData",
                dataType: "json",
                success: RenderPagedData,
                error: function (response) {
                    $('.error-load').show();
                    $('#imgLoading').hide();
                }
            });

        });

​        $("#btnMostRecent").click(function(){
           alert("clicked");    
      });

    });
</script>   

When i run the page in the console of Firefox it shows the below err -

SyntaxError: illegal character $("#btnMostRecent").click(function(){

enter image description here

Am i missing something..?

Please help and thanks in advance..!

4

There are 4 best solutions below

5
On

enter image description here There is a '?' before $("#btnMostRecent").click(function(){ line.

? $("#btnMostRecent").click(function(){ alert("clicked");
});

<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script>


    $(document).ready(function () {
        $('.error-load').hide();
        $('#imgLoading').hide();


        $("#BtnLoadMore").click(function () {
            $(this).hide();
            var lastArticleId = $('#hdnLastArticle').val();
            var sortOrder = $('#<%= hdnSortValue.ClientID  %>').val();
            alert(sortOrder);
            $('#imgLoading').show();
            $.ajax({
                type: "POST",
                contentType: "application/json; charset=utf-8",
                data: '{"RowId":"' + lastArticleId + '", "SortOrder":"' +sortOrder + '"}',
                url: "http://blogs-test.com/themes/blogs/vitalvotes/LoadService.aspx/GetNextData",
                dataType: "json",
                success: RenderPagedData,
                error: function (response) {
                    $('.error-load').show();
                    $('#imgLoading').hide();
                }
            });

        });

        $("#btnMostRecent").click(function () {
            alert("clicked");
        });

});
</script>
</head>

<body>

</body>

</html>
6
On

Are you copy and pasted from somewhere the code ? Here is the pic and found the red dot :

enter image description here

Remove that and should be okay

0
On

I have tried your code and getting the same error you mentioned. Can you replace the following code with your code? I have removed the special character.

<script type="text/javascript">

    $(document).ready(function () {
        $('.error-load').hide();
        $('#imgLoading').hide();


        $("#BtnLoadMore").click(function () {
            $(this).hide();
            var lastArticleId = $('#hdnLastArticle').val();
            var sortOrder = $('#<%= hdnSortValue.ClientID  %>').val();
alert(sortOrder);
            $('#imgLoading').show();
            $.ajax({
                type: "POST",
                contentType: "application/json; charset=utf-8",
                data: '{"RowId":"' + lastArticleId + '", "SortOrder":"' +sortOrder + '"}',
                url: "http://blogs-test.com/themes/blogs/vitalvotes/LoadService.aspx/GetNextData",
                dataType: "json",
                success: RenderPagedData,
                error: function (response) {
                    $('.error-load').show();
                    $('#imgLoading').hide();
                }
            });

        });

        $("#btnMostRecent").click(function(){
           alert("clicked");    
      });

    });
</script> 
0
On

If you have copied the code from a source which supports Unicode encoding, then you would get the error because, ' and " is a single quote (which we use while coding) and and are also quotes. If the code is copied from such a source, dont forget to remove the unsupported characters.

PS. jQuery doesn't support unicode.

To avoid this problem in future, copy the code to notepad (plain text) and then copy from there, and try pasting again to your code editor!!