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!

  • 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 5:43
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 :/

  • Make sure this cometd plugins js is included; – itzmukeshy7 Apr 16 '16 at 9:47
  • If you can share the js file you have included in which order may help to figure out problem little bit faster; – itzmukeshy7 Apr 16 '16 at 9:48
  • If this post solved your init question, you should accept it as correct. – Adrian Larson Jul 26 '16 at 12:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.