简体   繁体   中英

Ajax Not Found (404) POST url

Im trying to submit a form using ajax to call the php file, but when I try to test it, the browser console prints the following error

在此处输入图片说明

Below is my ajax post code

$( document ).ready(function() {
    $("form").submit(function(e) {
        e.preventDefault(); // prevent page refresh

        var email = $("#email").val();

        if (validateEmail(email)) {

            $.ajax({
                type: "POST",
                url: "php/send_form.php",
                data: $(this).serialize(), // serialize form data
                success: function(data) {
                    document.getElementById("successfullySentForm").style.display = "block";
                },
                error: function() {
                    document.getElementById("genericError").style.display = "block";
                }
            });

        } else {

            document.getElementById("wrongEmailFormat").style.display = "block";

        }
    });
});

Im running this website in my webserver.

Use $_SERVER['DOCUMENT_ROOT'] to solve path related problems.

Example: $_SERVER['DOCUMENT_ROOT'].'/path/to/file';

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM