weixin_33676492 2017-11-05 17:44 采纳率: 0%
浏览 19

找不到Ajax(404)POST网址

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

enter image description here

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.

  • 写回答

1条回答 默认 最新

  • 关注

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

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

    评论

报告相同问题?