You are missing with e.preventDefault()
in your script. What is happening here is your action is hit by both script and normal post. So if you put e.preventDefault()
like below, then it will prevent browser's default postback and only javascript's code will execute your request.
$("#myForm").on("submit", function(e) {
e.preventDefault();
window.location.href = $(this).attr("action");
});