It is giving me errors on url = url.replace("/post?u=", "/post-json?u="); because $("form#mc-embedded-subscribe-form") can't fetch the right element due to the document not being loaded. As a consequence, .attr("action") will return undefined. Try adding a .ready event listener to the whole code.

Also, the right way is $("#mc-embedded-subscribe-form").

To add on that, you also have this on your HTML:

<form action"[...]">

You forgot the = between action and its value. It should look like this: