Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

share|improve this question

1 Answer 1

up vote 2 down vote accepted

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.