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

Improve your online store with our extensions.
About: Squarespace Circle Leader since 2017. I value honesty, transparency, appreciation and great design ♥.
Work: Squarespace Developer and founder of SF Digital, building the features Squarespace didn't include™.
Content: Links in my posts may refer to SF Digital products or may be affiliate links.

Buy me a coffee

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.