Jump to content

jQuery click event not working sometime

Recommended Posts

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 
})


Link to comment
  • Replies 5
  • Created
  • Last Reply

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

About me: I've been a SQSP User for 18 yrs. I was invited to join the Circle when it launched in 2016. I have been a Circle Leader since 2017. I don't work for Squarespace. I value honesty, transparency, diversity and good design ♥.
Work: I founded and run SF.DIGITAL, building Squarespace Extensions to supercharge your commerce website. 
Content: Views and opinions are my own. Links in my posts may refer to SF.DIGITAL products or may be affiliate links.
Forum advice is free. You can thank me by clicking one of the feedback emojis below. Coffee is optional.

Link to comment

Archived

This topic is now archived and is closed to further replies.

Guest
This topic is now closed to further replies.
×
×
  • Create New...

Squarespace Webinars

Free online sessions where you’ll learn the basics and refine your Squarespace skills.

Hire a Designer

Stand out online with the help of an experienced designer or developer.