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

jQuery click event not working sometime


3rddigital
Go to solution Solved by paul2009,

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
Link to post
  • Answers 5
  • Created
  • Last Reply

Top Posters For This Question

Popular Days

Top Posters For This Question

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 helping Squarespace users by building the features that Squarespace didn't include.
Explore our range of Squarespace Extensions, including the Wishlist, and Datepicker Extension or book a Squarespace Expert for 1:1 help. Note that links in my posts may be affiliate links.

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 ?

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

×
×
  • Create New...