0

The following code works well but does not work in wordpress please assist:

$(document).ready(function () {
    var ac_config = {
        source: "ajax.php",
        select: function (event, ui) {
            $("#facility_name").val(ui.item.facility_name);
        },
        minLength: 1
    };
    $("#facility_name").autocomplete(ac_config);
});

The problem is that the ajax.php is file is not being seen as the source. Can someone help with correctly declaring the source?

0

Shouldn't you add full path of the ajax.php in your code.

If your ajax.php file is in theme folder then you can use get_template_directory_uri() function to define file path. So this should be your code.

$(document).ready(function () {
    var ac_config = {
        source: "<?php echo get_template_directory_uri(); ?>/ajax.php",
        select: function (event, ui) {
            $("#facility_name").val(ui.item.facility_name);
        },
        minLength: 1
    };
    $("#facility_name").autocomplete(ac_config);
});

If your ajax.php file is located somewhere else then use path accordingly.

Your Answer

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

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