RKN Posted August 27, 2022 Posted August 27, 2022 (edited) I uploaded a simple text file to my Squarespace site (Business Plan subscription, 1 year auto-renewal). I injected javascript into the footer to test code to read the contents of the file (see below). The output in the Dev console (Firefox) is not the contents of the file I expected, but rather - Records: <empty string>. I've used this technique successfully on Wordpress sites. Any idea why this isn't working on Squarespace? UPDATE: Looking deeper, is it possible the responseText is empty because Squarespace doesn't put 'Access-Control-Allow-Origin' in the request's response header? If so, is there another approach I can use to accomplish my goal? <script type="text/javascript"> rawFile = new XMLHttpRequest(); rawFile.open("GET", 'https://lily-pike-4bpy.squarespace.com/s/motd.txt', false); rawFile.onreadystatechange = function () { if(rawFile.readyState === 4) { if(rawFile.status === 200 || rawFile.status == 0) { var allText = rawFile.responseText; console.log('Records:',allText); } } } rawFile.send(null); </script> Edited August 27, 2022 by RKN Updated info
Beyondspace Posted September 6, 2022 Posted September 6, 2022 On 8/27/2022 at 7:51 AM, RKN said: I uploaded a simple text file to my Squarespace site (Business Plan subscription, 1 year auto-renewal). I injected javascript into the footer to test code to read the contents of the file (see below). The output in the Dev console (Firefox) is not the contents of the file I expected, but rather - Records: <empty string>. I've used this technique successfully on Wordpress sites. Any idea why this isn't working on Squarespace? UPDATE: Looking deeper, is it possible the responseText is empty because Squarespace doesn't put 'Access-Control-Allow-Origin' in the request's response header? If so, is there another approach I can use to accomplish my goal? <script type="text/javascript"> rawFile = new XMLHttpRequest(); rawFile.open("GET", 'https://lily-pike-4bpy.squarespace.com/s/motd.txt', false); rawFile.onreadystatechange = function () { if(rawFile.readyState === 4) { if(rawFile.status === 200 || rawFile.status == 0) { var allText = rawFile.responseText; console.log('Records:',allText); } } } rawFile.send(null); </script> Can you share your site with the protected password so I can take a look? BeyondSpace - Squarespace Website Developer 🖼️ Lightbox Studio (Pinch/Zoom images, videos - PDFs Lightbox - ...) </> 🗓️ Delivery Date Picker (Date picker form field) Gallery block 7.1 workaround </> 🤖 Ask me anything
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment