Jump to content

Does Squarespace supports XHR request?

Recommended Posts

Hi all, I am trying to execute API calls from Squarespace , and I was wondering if the dev platform supports XHR request?
Has anyone attempted this before? If yes, any working sample code?
I am using five template. 

** 
I kept getting error below:

[Error] Failed to load resource: the server responded with a status of 500 (Internal Server Error) (login, line 0)

Link to comment
  • Replies 3
  • Created
  • Last Reply

Please provide a more detailed explanation of what you are trying to achieve, what you've tried so far and include a working link to the website. If the site isn't live, we need you to set a password in the visibility settings and tell us what it is.

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 have been getting error below. 
 
"HTTP 500 ERROR for XHR Request"
 
(See brief screenshot)

What I am trying to do:
1. Send API request from Squarespace to Splunk (www.splunk.com)
2. Click the button I should be able to see a list of apps in my Splunk server.

My example code: 
(under /template/pages/)
(created as static page)
<html>
  <head>
    <meta charset="utf-8">
    <title>How to start a Splunk session</title>
    <squarespace:script type="text/javascript" src="jquery.min.js"></script>
    <squarespace:script type="text/javascript" src="splunk.js"></script>

    <script type="text/javascript" charset="utf-8">
    function displayApps() {
        var http = new splunkjs.ProxyHttp("/proxy");

        // Create a Service instance and log in
        var service = new splunkjs.Service(http, {
            username: "XXXX",
            password: "XXXX",
            scheme: "https",
            host: "XXXX",
            port:"8089",
            version:"5.0"
        });


        // Verify we logged in

        // Print installed apps to the console to verify login
        service.apps().fetch(function(err, apps) {
            if (err) {
                alert("Error listing apps");
                return;
            }

            var myapps = "";
            var appsList = apps.list();
            for(var i = 0; i < appsList.length; i++) {
                myapps += "App " + i + ": " + appsList[i].name + "<br/>"
            }

            document.getElementById("applist").innerHTML=myapps;
        });

    }
    </script>
</head>
<body>
    <button type="button" onclick="displayApps()">Log in and list apps</button>
    <p id="applist"></p>
</body>
</html>


I have got two scripts under "/template/scripts"

jquery.min.js
splunk.js https://github.com/splunk/splunk-sdk-javascript/blob/master/client/splunk.js

 

1763254307_ScreenShot2020-01-03at7_36_36pm.thumb.png.40f0fd0406c30f1cee054691168ecf9e.png

Link to comment

Squarespace won't prevent you from writing client-side JavaScript code that connects to external APIs. Therefore the issue must be something about your JavaScript or your settings in Splunk. I'm not familiar with the details of Splunk, but there is this (which you may have already reviewed).

If a response helped you out, send a 'Like' 👍 (bottom-right) and/or 'Upvote' vote.jpg.c260784ece77aec852b0e3049c77a607.jpg (top-left)

Link to comment

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.