Is there any solution to detecting if a POST have been sent with jQuery?
My situation is that I have a WP-plugin (Contact form 7) which is sending the data through a jQuery ajax-function. When the form is filled right (validates) the user should be sent to page X.
I have tried with the following without any good results:
if ($(".wpcf7-mail-sent-ok").is(":visible")){
window.location.href = "http://stackoverflow.com";
});
I think this doesn't work because the class "wpcf7-mail-sent-ok" is showing up only when the form is sent and valid by jQuery. So it isn't there to be "detected" for my above code.
How do I solve this issue?
You can use something like Fiddler to inspect the traffic or Chrome -> right click -> "inspect element" -> "Network".
Find that ajax on your page and look for its success
function, put an alert('hello') in there and you'll know if it gets executed.
if($(".wpcf7-mail-sent-ok").length)
You can detect DOM insertions with DOMNodeInserted
event. If you think wpcf7-mail-sent-ok
is being inserted only after the ajax call then you can bind on this event.
$(document).on('DOMNodeInserted', '.wpcf7-mail-sent-ok', function() {
window.location.href = 'http://stackoverflow.com'
})