0

I am getting this error from a jquery script on a specific page which performs an ajax call... and as far as I know it is generally an error caused by a missing } or )... but I have looked through the code over and over again and cannot see anything that is missing. Are there any other possible reasons this error could be flagged?

 $('#socialMedia img').click(function() {
            var id = $(this).prop('id').toLowerCase();
            $.ajax({
                    url: "./socialMedia/" + id + ".php",
                    success: function(msg) {
                            $('.socialLink').css('opacity', '0.4');
                            $(this).css('opacity', '0.9');
                            if ($('#Feed').css('display') != 'none') {
                                    $('#Feed').slideToggle(400, function() {
                                            $('#Feed').html(msg);
                                    });
                            }
                            else
                            {
                                    $('#Feed').html(msg);
                            }
                            $('#Feed').slideToggle(400);
//                              if ($('#'+id+'Script').length <= 0) {
//                                      $('head').append('<script type="text/javascript" src="./script/' + id + '.js" id="'+id+'Script"></script>');
//                              }
                            //alert(msg);
                    }
            });
    });

EDIT: you can "see" (you won't actually see anything as the error causes the page never to be loaded) the page by going to http://www.luketimoth.me... and then clicking "contact.me" (it is an AJAX site, and I have not yet implemented any handling of url specifiers)

2
  • Is this code the entire contents of your javascript file? And is it the only javascript file being loaded? Also, save yourself some trouble looking over and over the code. Use jshint.com Commented Aug 4, 2013 at 19:16
  • This was all the JS code that was being loaded in the AJAX call, yes. Problem is sorted now, as you may see. Thanks for the link. It'll certainly come in handy! Commented Aug 4, 2013 at 20:23

1 Answer 1

1

The problem is in the AJAX response at this URL:

http://www.luketimoth.me/pages/contact.me.php

The ending </script> tag actually causes the end of that script portion - double-slash comment syntax is for javascript, the HTML parser doesn't respect it and ends the script section right there.

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

2 Comments

Okay. That sorted that problem out. Thanks. I am beginning to think that I ought to be loading in javascript in a different way, e.g. appending a script tag to the head on page load might be a smarter way of doing things.
Yup. I'd just stick it at the bottom, right before the closing body tag, but yeah, loading a remote file avoids the HTML parsing edge cases.

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.