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

1 Answer
1

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

Leave a Reply

Your email address will not be published. Required fields are marked *