I have a form and one of the fields is an email with id email and after the user inputs their email and clicks outside the field, I wish to get the value of the email and then use ajax to pass that value to another php file that will run a wordpress function called email_exists() and then pass that result back to ajax. Right now I just want to console log the result value and then later I will add additinal jquery to alert the user in the form.

I have my current code below and it is not showing anything in the console even if I put an email that does exist on my wordpress site and I can't figure out why. Any help would be great, thanks!


$(function() {     
    $("#email").blur(function () {
    var email = $(this).val();
        url: 'validation.php',
        type: ' POST',
        data: {
            email: email
        success: function(response) {
        error: function(response) {


$response = email_exists($_POST['email']);
echo $response;
  • It's extreme bad practice to make requests to a PHP file in your theme or plugin, it's fragile and has security problems. If you want to make AJAX requests to WordPress, then they must be done via the REST API or Admin AJAX. If you do not then WordPress functions will be unavailable and you'd have to perform the dangerous operation of bootstrapping WordPress in that file.
    – Tom J Nowell
    Jul 30 at 16:36


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.