0

I am having a little fun and working with the Streaming API. It was working fine yesterday, and I was able to subscribe without any issues. However, now I am getting this error:

Cannot read property 'init' of undefined

I am pretty certain I have not changed any of the code and the static resources that are being called definitely have not been edited or changed. I even as a precautionary measure updated them again before posting this.

JQuery:

$(function () {
    $("#finalise").click(function () {
        $.cometd.init({
            url: window.location.protocol + '//' + window.location.hostname + '/cometd/24.0/',
            requestHeaders: {
                Authorization: 'OAuth {!$Api.Session_ID}'
            }
        });
    });
});

This should basically initialise the connection on click of a button that I have on my page.

I am absolutely baffled at this, especially with me being new to JQuery :/

Any help would be very largely appreciated!

Adrian Larson
  • 149,971
  • 38
  • 239
  • 420
Tim
  • 1,373
  • 3
  • 13
  • 27
  • The error suggests that the CometD JavaScript has not bound to jQuery as it should, hence $.cometd is undefined. I suggest you check the "Network" tab of your browser's "Developer Tools" to ensure that both the jQuery and CometD JavaScript was found and then also check for any errors in the JavaScript console. This may help. – Keith C Jul 22 '15 at 20:32
  • Have you checked loaded resources that comet files have been loaded? – ashishcloud Feb 13 '16 at 05:43

1 Answers1

0

Thanks @Keith for pushing me in the right direction... for some strange reason the CometD library doesn't like the Google API's JQuery -_-

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

If this is placed before $.cometd.init(); then it causes an issue.

However, now I also have the issue of when I am calling $.cometd.subscribe() it is also causing issues :/

Tim
  • 1,373
  • 3
  • 13
  • 27