SHCP Posted December 25, 2023 Posted December 25, 2023 (edited) Hello, I need to use a .js file which contains an ajax call to a .json file. What I tried: Adding a disabled page with two links pointing the two files, which I uploaded, and then copy-pasted the URL (/s/js.js and /s/json.json), adding <script src="/s/js.js"></script> to my page. The assets library section doesn't allow uploading of .js or .json. The above generates a CORS error when the .js calls the json: Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://static1.squarespace.com/static/60ec2975d230b9076ec61068/t/658808ec766c4f231170302f/1703414009896/new_list.json. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing). Status code: 404. I then used the static1... URL above instead of the /s/json.json. No luck. I also used the static1... URL for the javascript itself (I got it from the browser's console). No luck. I injected the js code on the whole site's header and footer. No luck. I copy-pasted the javascript code on a page code block: my javascript code has the 'display code' switched on and greyed out, so that the raw code is always displayed on my site (yes, logged out, in private mode, etc.). Adding a HTML code with the <script> tage still gets ignored. I even inserted the whole json in a <script> tag in the page. Since it's a big json the page times out or says 'connection failed' so that's also not an option. Is what I'm doing so impossibile? I have a business plan. The SquareSpace support replied to my request with a non-answer (i.e. that I should be knowing what I'm doing and linked to resources I already perused). Let me also add that the code is working fine on my local MAMP so there is no issue whatsoever with the code itself. It's just a javascript file that makes and ajax call to a json file to populate a datatables table. I'd highly appreciate any help. Luca Edited December 25, 2023 by SHCP
SHCP Posted December 25, 2023 Author Posted December 25, 2023 (edited) For now I solved by putting my file on another hosting I own and then reference it in my page's <head>. It works like a charm and I don't have to deal with Squarespace's very limited support for custom code (as stated by themselves). Edited December 25, 2023 by SHCP
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment