Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
Advanced Search
  • 0
LianLim

Does Squarespace supports XHR request?

Question

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)

Share this post


Link to post

3 answers to this question

Recommended Posts

  • 0

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.


sf-digital-signature-logo-email145.png.46606a2288a2847f44d81b9b7b58f3a5.png
Hi, I'm Paul, founder of SF Digital, a specialist company building the features that Squarespace didn't include
I am a Squarespace Expert and Squarespace Circle Leader with a
strong reputation on the Squarespace Forum. I'm trusted by thousands of Squarespace users worldwide, including designers, freelancers, business owners and agencies. My extensions add capabilities to Squarespace websites around the globe. They include the Enquiry Form ExtensionDatepicker Extension and Age Verification ExtensionNeed a custom Squarespace extension? Tell me about the functionality you need. Note that some links in my posts may be affiliate links. Book a Squarespace Expert when you need help.

Share this post


Link to post
  • 0

@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

Share this post


Link to post
  • 0

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)

Share this post


Link to post

Create an account or sign in to comment

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


×
×
  • Create New...