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
There are WordPress ajax hooks that helps to create function using ajax. WordPress allows admin ajax to run any function. Following code is help to use custom ajax in wordpress.
HTML Part
Turns out you can hook a function into the ajax functions
http://www.1stwebdesigner.com/css/implement-ajax-wordpress-themes/
I think one easy method is to create a new template and assign this template to a new page.
then you can write your code in this template file and use the url of the page for ajax request
Try this, It easiest way, I have worked on this many times:
step 1: Add these code snippets in functions.php
Step 2:
Now call the ajax in your template page