0

I am trying to call php file located in the same directory as HTML using $.post() method of Ajax. however, i am getting a file not found(404) error.

below is the code I am using.

$(document).ready(function(){
        $("#formSubmit").on("click",function(){             

            alert("in iquery");
            $.post("./path.php",                        
                    function(){
                        alert("success1");
                        }                       
            );
        });
    });

I have tried calling other php file located in the subdirectory with "./PHP/path2.php". Its resulting in the same error.

Please help.

user1978142
  • 7,946
  • 3
  • 17
  • 20
Tejaswi
  • 33
  • 1
  • 8

1 Answers1

1

If the php file is in the same dir, then $.post("path.php", function() { alert("success"); }); without ./ should work. Also, handle the submit event on the form, which is better than the click event on the submit button, and make sure to disable the default behavior of the submit event with event.preventDefault() or a return false after the AJAX call.

DavideR
  • 570
  • 4
  • 18