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

jQuery click event not working sometime

Question

Hi

I have created one page and i am sending data to my other site through third party api url on jquery click event , but when i am submitting form my api is not calling.

It's sometime work and sometime not work.

Can you please tell me is anything blocking squarespace ?

I have put my code inside Page Settings -> Advanced.

E.x


$(document).on('click', 'target', function () { 
// ajax code here 
})


Edited by Paul2009

Share this post


Link to post

5 answers to this question

Recommended Posts

  • 0

This is because of Ajax - not the Ajax that you want to use in your code, but the Ajax that is built into the newer Squarespace templates.

There are currently two issues:

  • Where the code is located. Code inserted into the Page Settings panel will not load when Ajax is enabled, unless the page is opened directly or refreshed. Code should be added to the Footer Injection or to a Code Block.

  • The code itself.

    $(document).on

    will only fire on a load of the full page, not an Ajax load. You need to trigger a function using Squarespace's onInitialize or mercury:load instead.

For a longer explanation of Ajax (that may help others who read this) see the guide I wrote here:

https://sf.digital/squarespace-solutions/why-doesnt-my-code-work-until-i-refresh-the-page

I hope that helps.

-Paul

Squarespace Expert & Professional Developer

Edited by Paul2009
Initial Revision

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 Developer 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 ExtensionDate Picker 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.

Share this post


Link to post
  • 0

Thanks for replay.

So do you mean i have to write code inside Settings->Advance->code-injection ->footer ?

But I have also tried that but same issue.

First time will not work if i am doing hard refresh then its work.

Can you please suggest me what i do ?

Share this post


Link to post
Guest
This topic is now closed to further replies.

×
×
  • Create New...