I’m trying to create ajax form submitting and validation with jQuery, but wordpress refuses to execute my code.
I’ve this snippet, working on http://jsfiddle.net
$(document).ready(function(){
alert("Test");
$('.sendbutton').click(function(){
var nimi = $('input[name=nimi]').val();
var viesti = $('textarea[name=viesti]').val();
$('.control-group').removeClass("error");
if(nimi == ""){
$('.control-group#nimi').addClass("error");
return false;
}
if(viesti == ""){
$('.control-group#viesti').addClass("error");
return false;
}
var message = $('#contact').serialize();
alert(message);return false;
$.ajax({
data : message,
error : function(){alert('Viestiäsi ei lähetetty. Yritä uudelleen?');},
success : function(){alert('Onnistui');}
});
return false;
});
});â
But it won’t work on wordpress, or on my theme. I’m using Roots theme (Twitter Bootstrap) and I’ve tried placing the code in plugins.js as jQuery UI is working and I placed it there, but no. Including the script from a different file
From codex :
http://codex.wordpress.org/Function_Reference/wp_enqueue_script#jQuery_noConflict_wrappers
You should use :