jquery - Submit form with ajax in wordpress -
i trying create jquery function send html form ajax. build standard html form post method , trying create jquery part , there problem. here code:
$(document).ready(function() { $('form').submit(function() { var formdata = $('form').serialize(); var href = 'http://stravomat.michalfolprecht.com/wp-admin/admin-ajax.php'; $.post(href, formdata, function(resp) { console.log(resp); if ( resp.success ) { console.log('success'); } else { console.log('alert'); } }); // stop form submitting normal way , refreshing page event.preventdefault(); });
});
i have php part on same page form , standard wordpress custom page template. jquery code in custom file , linked wordpress header. not know if should use ajax url or use url page. when try use code console log give me number 0 that's all. can me this?
thanks reply.
michal.
as per wordpress structure
you need pass action
variable alongwith form , define function in wordpress plugin/theme catch action using add_action method.
see more details: http://codex.wordpress.org/ajax_in_plugins
Comments
Post a Comment