Content by JSON


(Andrea Ruske) #1

Return Content by Json

I am a content editor but had to set up a website and was using a half finished template. I have one error I can’t get my head around. I will get a professional programmer in if I have to but I thought I try this first as I have no budget for this setting up this site.
My site has a third level navigation, if I click on a link in the navigation the setup on the third level only refreshes the content area and the url when using json

code is

    getPagePayload: function(params) {
        $('#content-stage-wrap').removeClass('ready').addClass('in-transition');
        params.layout = (params.layout == undefined) ? 'ajaxload' : params.layout; 
       params.layout = (params.layout == undefined) ? '' : params.layout;

$.ajax({
url: ‘/new/_resources/design/content-by-json’,
dataType: ‘HTML’,
type: ‘GET’,
data: {
‘pageid’: params.assetid,
‘SQ_PAINT_LAYOUT_NAME’: params.layout
},
success: function(response) {

                // if the request includes a callback, use it.. (a function to handle the ajax response)
                { (params.callback != 'undefined' && typeof params.callback == 'function') }
                   params.callback.call(this, response); // brings the scope to the callback
              

                
            },
            error: function(error) {
                console.log(error);
            }

My problem is it is displaying the extra page instead of hiding it. What is the best way of not having it displayed?
Where do I start looking to have this “shadow page” not displayed? Sorry if this is a stupid question but I just started to work with Squiz and I am not a programmer.


(Serge) #2

Let’s deconstruct this …

$('#content-stage-wrap').removeClass('ready').addClass('in-transition'); params.layout = (params.layout == undefined) ? 'ajaxload' : params.layout; params.layout = (params.layout == undefined) ? '' : params.layout;

… if params.layout is undefined, set it to the string ‘ajaxload’ otherwise set it to itself … that’s redundant. Then, if params.layout is undefined (again??) set it to an empty string otherwise set it to itself.

better logic that doesn’t create an error:

if(typeof params.layout == "undefined") params.layout = 'ajaxload';

next bit …

$.ajax({ url: '/new/_resources/design/content-by-json', dataType: 'HTML', type: 'GET', data: { 'pageid': params.assetid, 'SQ_PAINT_LAYOUT_NAME': params.layout }, success: function(response) { // if the request includes a callback, use it.. (a function to handle the ajax response) { (params.callback != 'undefined' && typeof params.callback == 'function') } params.callback.call(this, response); // brings the scope to the callback }, error: function(error) { console.log(error); }

Here we are calling a page /new/_resources/design/content-by-json that is going to return some HTML, we’re passing it a pageid and a SQ_PAINT_LAYOUT_NAME parameter. Upon success, it checks if there is a callback function … here I have no idea if there is such a function defined somewhere else, that hasn’t been provided. If it exists, it is going to be called with the response (the html returned).

Now one would expect that all this data coming back would end up into some variable called “response” and not be displayed anywhere. So there are two options here:

either A. there is a function that has been set for params.callback and that function adds the HTML to the page (DOM)
or B. for some reason the AJAX call fails to operate properly and the result gets loaded into the browser. To investigate that I’d use Chrome developer tools (ctrl+shift+i) and look at the network tab and refresh the page to see what is actually going on when the AJAX call is being made.

These are the pointers I can give, the rest is for a developers to troubleshoot :wink:


(Andrea Ruske) #3

Thanks very much appreciated I will try to figure it out. happy to be a content editor and not playing with setups in Squiz :slight_smile:


(Serge) #4

Disclaimer: I don’t work for Squiz, I’ve just been fiddling with Javascript on Squiz Matrix recently. Would be good if we could improve that aspect of the tool as it empowers community to customize it.


(Bart Banda) #5

How did you go Andrea? Did you work it out?