My question pertains to where I should create an ajax function that I’d like to call from my page view.
I am using a jQuery validator on a custom form that should check the inputted zipcode against my database of valid zipcodes.
I just need to know where this function should exist.
Normally when using a non wordpress site I’d create a PHP file with my ajax functions and call them by referencing the URL to this page and passing some parameters.
How can I achieve this with wordpress? Where can i explicitly call a php file and pass it arguments?
Note: I’d like to call the ajax function like so:
$.post('http://mysite.com/ajax-functions.php?fxn=zipcodes',
{zipCode:00000},
function(response){
// do stuff
});
Thanks
In WordPress the way of handling Ajax calls is a bit different the plain PHP but still very simple, all ajax calls should be to
wp-admin/admin-ajax.php
and you just define your own functions by hooks,Take a look at What’s the preferred method of writing AJAX in WordPress