Kev_B
Joined 10 years ago
Joined 10 years ago
It also took me a bit of back and forth to get it working. Reasons are due to Khoros Classic using an older version of jQuery and some specific JSON requirements:
Here's the resulting evolution of your v1 code that works on my end:
<#assign boardID = coreNode.id />
<button id="subscribe">AJAX test</button>
<@liaAddScript>
(function($){
$(document).ready(function(){
$("#subscribe").on( "click", function() {
$.ajax({
url: "/api/2.0/subscriptions",
contentType: "application/json",
dataType: 'json',
data: JSON.stringify({
type:"subscription",
target:{
type:"board",
id:"blueprints"
}
}),
type: 'POST'
}).done(function(response) {
console.log('Success');
}).fail(function() {
console.log('Fail');
})
});
});
})(LITHIUM.jQuery);
</@liaAddScript>Bonus tip:
Looking at the details in your browser's network tab will reveal that quite often the HTTP error code is hiding a different more detailed "developer message" debug info in the return data. E.g. here's a HTTP 500 error that is hiding a message about non-stringified content:
Hi Kev_B
I think I know what is going on. I assume you are adding your component to the "Group Hub Page". If someone is not a member, I think a different page actually loads and your code never runs. It is called "Closed Membership Page" and can be edited in studio so you can add whatever you want there for non-members.