RKN Posted August 27, 2022 Share 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 Link to comment
Beyondspace Posted September 6, 2022 Share 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 (Enable Pinch/Zoom on lightbox) 🗓️ Delivery Date Picker (Squarespace Date format) 💫 Animated Buttons (Referral URL) 🥳 Sparkplugin Customisations Browsers (Browse +100 Spark plugin customisations) 🥳 Elfsight Template Browsers (Browse +1000 Elfsight widget Templates) If you find my answer useful, let's leave a like or upvote so others with the same issue can find their solution. Thank you! Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment