Qlocx Posted August 18, 2020 Share Posted August 18, 2020 Hello, I'm trying to inject a piece of Javascript code in to a page that has a form. What I want is to run the Javascript code with an XMLHttpRequest and wait for a response (onloadend) and then continue with the form post to the Squarespace servers. I can pause the execution of the form post, but I don't know how to resume it! I've tried things like: document.getElementsByClassName(the button class)[0].click() and document.querySelector('[data-form-id="<form id>"]').submit() They give 403 Forbidden How would I do it? Thanks! Link to comment
Guest Posted August 19, 2020 Share Posted August 19, 2020 As per my understanding, what you want to try is inject an Ajax request before submitting the form. But my question is why you want to do that, if you are doing that for validation then you won't use Ajax request for that, server sends the error response and you just need to display the errors. Now, if you want to send the Ajax request then you have to submit the form manually using JavaScript. When the user clicks the submit button, you preventDefault() in the function and then send your Ajax request to squarespace server and it will return the response and then you write the code that submit the post request to the server with form data. Link to comment
Guest Posted August 22, 2020 Share Posted August 22, 2020 On 8/19/2020 at 5:39 PM, ankitlathiya said: As per my understanding, what you want to try is inject an Ajax request before submitting the form. But my question is why you want to do that, if you are doing that for validation then you won't use Ajax request for that, server sends the error response and you just need to display the errors. Now, if you want to send the Ajax request then you have to submit the form manually using JavaScript. When the user clicks the submit button, you preventDefault() in the function and then send your Ajax request to squarespace server and it will return the response and then you write the code that submit the post request to the server with form data. How can I add an ajax to my form? I tried adding a listener to the submit button but it didn't trigger. Can you share a code sample? I've added jquery to my site too. Link to comment
Qlocx Posted November 10, 2020 Author Share Posted November 10, 2020 On 8/19/2020 at 7:39 PM, ankitlathiya said: As per my understanding, what you want to try is inject an Ajax request before submitting the form. But my question is why you want to do that, if you are doing that for validation then you won't use Ajax request for that, server sends the error response and you just need to display the errors. Now, if you want to send the Ajax request then you have to submit the form manually using JavaScript. When the user clicks the submit button, you preventDefault() in the function and then send your Ajax request to squarespace server and it will return the response and then you write the code that submit the post request to the server with form data. Hi, thank you for your response! Its not related to validating the form, its for sending the data to another server also. Yes I can use preventDefault() like I said in my original post: "I can pause the execution of the form post". But I cannot resume it. How do I "then you write the code that submit the post request to the server with form data." ? Thats my big nut to crack! Thank you Link to comment
Recommended Posts
Archived
This topic is now archived and is closed to further replies.