Jump to content

How do I add mercury loading for Ajax pages to my site?

Recommended Posts

I want to be able to link xml data. I’m following along a tutorial for Ajax with Mozilla and I know it works. I also know other people have had success with Mercury, but, whenever I try to do it, it fails. Can someone please walk me through that and how to get the exact path to use for the Ajax file? 

Link to comment

We'll need more information if we are to help you. Which tutorial are you following? What are you trying to achieve? 

Improve your online store with our extensions.
About: Squarespace Circle Leader since 2017. I value honesty, transparency, appreciation and great design ♥.
Work: Squarespace Developer and founder of SF Digital, building the features Squarespace didn't include™.
Content: Links in my posts may refer to SF Digital products or may be affiliate links.

Buy me a coffee

Link to comment

@paul2009 I’m following this tutorial. I’m volunteering for a non profit and it would make my life a lot easier if I could store sensitive data in an xml file and retrieve it as needed. I know that you are limited with the backend, and, squarespace seems to want to play nice with Ajax, but, whenever I tried all the online solutions, I could not get it to work.

Edited by Jake235
Link to comment
20 minutes ago, Jake235 said:

whenever I tried all the online solutions, I could not get it to work

Can you be more specific? What JSON data are you trying to query, and why? Also, can you provide a working link to the page where you are trying to do this?

Improve your online store with our extensions.
About: Squarespace Circle Leader since 2017. I value honesty, transparency, appreciation and great design ♥.
Work: Squarespace Developer and founder of SF Digital, building the features Squarespace didn't include™.
Content: Links in my posts may refer to SF Digital products or may be affiliate links.

Buy me a coffee

Link to comment
28 minutes ago, Jake235 said:

I believe squarespace has its own flavor of Ajax

I think you've picked up mixed messages. If you want to use Ajax to read data then it works exactly the same on Squarespace as it does on any other web builder. 

I suspect you've been reading about Squarespace's own Ajax Page Loader (Mercury) which they used on Squarespace 7.0 for their Brine family of templates. This is used to load site content more quickly by loading the page body only, not the headers and footers. It isn't related to writing your own Ajax requests and isn't used on newer Squarespace 7.1 sites.

Edited by paul2009

Improve your online store with our extensions.
About: Squarespace Circle Leader since 2017. I value honesty, transparency, appreciation and great design ♥.
Work: Squarespace Developer and founder of SF Digital, building the features Squarespace didn't include™.
Content: Links in my posts may refer to SF Digital products or may be affiliate links.

Buy me a coffee

Link to comment

@paul2009, I think you're exactly correct. But, question, since I am using squarespace 7.0, do I need to use it? I am using Squarespace 7.0 and I thought that in order to use AJAX that I had to do something special. I think that the issue is with accessing the squarespace static API on a trial site. I am, however, able to access my Github pages. I have an example of my working code here, and, now that I have a working code, I can play around with things and break things, then, go back to here when I mess up. I believe that I followed this guidance.

window.addEventListener('load', loadXMLDoc);
window.addEventListener('mercury:load', loadXMLDoc);

function loadXMLDoc() {
    var xmlhttp = new XMLHttpRequest();
 
    xmlhttp.onreadystatechange = function() {
        if (xmlhttp.readyState == XMLHttpRequest.DONE) {   // XMLHttpRequest.DONE == 4
           if (xmlhttp.status == 200) {
               document.getElementById("demo").innerHTML = xmlhttp.responseText;
           }
           else if (xmlhttp.status == 400) {
              alert('There was an error 400');
           }
           else {
               alert(xmlhttp.status);
           }
        }
    };
 
    xmlhttp.open("GET", 'https://#######.github.io/portfolio/Ajax_material/test.txt', true);
    //This should work
    xmlhttp.send();
}

 

Edited by Jake235
Link to comment
  • 4 weeks later...
On 3/13/2022 at 7:00 PM, paul2009 said:

I think you've picked up mixed messages. If you want to use Ajax to read data then it works exactly the same on Squarespace as it does on any other web builder. 

I suspect you've been reading about Squarespace's own Ajax Page Loader (Mercury) which they used on Squarespace 7.0 for their Brine family of templates. This is used to load site content more quickly by loading the page body only, not the headers and footers. It isn't related to writing your own Ajax requests and isn't used on newer Squarespace 7.1 sites.

@paul2009, I know it’s been a while. I am learning the AJAX language better. Can squarespace allow AJAX post requests too? Would I have to prevent the form from submitting and do an event listener? 

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

×
×
  • Create New...

Squarespace Webinars

Free online sessions where you’ll learn the basics and refine your Squarespace skills.

Hire a Designer

Stand out online with the help of an experienced designer or developer.