I am developing custom theme for WP and I have a problem with ajax callbacks…
This is my header:
<script>
//alert("Data Loaded");
$('#domaincheck').submit(function(){
alert("Button pressed");
$.post('<?php bloginfo('template_directory'); ?>/check.php', $(this).serialize(), function(data){
alert("Data Loaded: " + data);
});
return false;
});
</script>
In my theme file i have simple form like:
<form id="domaincheck">
Name: <input type="text" name="urname">
Birthplace: <input type="text" name="urbirth">
<input type="submit" name="submit" value="Submit">
</form>
Now when I click submit button – pages just reloads 🙁 when I move this out of WordPress everything is working properly. Is there a way to make this to work in WordPress ? Also another strange thing is when I wrap JS code in “document ready” – javascript is not working at all…. without documentready it displays the Alert – but not the callback – it just reloads page… Once again – outside of wordpress template it works like it should.
Thanks, Peter
I have done on my Localhost and this is doing a ajax call very fine:
i
added one main jquery pluginreference inheader.phpfile at<head>and this one is the
check.phpfile php code:and i got the alert of the posted data.
try this and see if this helps.