Not working contact form php, ajax, jquery?

I "pulled" my layout on WordPress. I have a popup window, js and php file for processing, at the stage handler php error occurs
Perhaps the problem is in Jquery, when submit the form, jquery falls.min.js?ver=5.3.1:2 POST localhost:8888/house-wp/contact.php 404 (Not Found)
this type of error.

Maybe someone faced?

$(document).ready(function() {
 $("#sendmail").click(function() { 
 //var form = $(this).serialize();
 type: 'POST', //submit Method 
 url: 'contact.php', //path to php file sender
 error:function() {
 $("#erconts").html("an error Occurred!");
 beforeSend: function() {
 $("#erconts").html("<p style='color: blue;'>information Sent...</p>");
 success: function(result){ // event after a successful appeal to the server and receiving a response
 $('#erconts').html(result); // show the text
 return false;



April 3rd 20 at 18:35
1 answer
April 3rd 20 at 18:37
You have not done api for wp. How to do the right thing - for beginners
as I understand it the problem is in the url
substituting the full path ( url: "localhost:8888/house-wp/wp-content/themes/house/co...') php function was performed.
But how to write this shorter? by analogy with the example, only to its file? - Meta commented on April 3rd 20 at 18:40
@Meta, for data transfer with php there is a function wp_localize_script. If the file is in your folder template, you can use get_stylesheet_directory_uri. - llewellyn_Harber commented on April 3rd 20 at 18:43

Find more questions by tags AJAXjQuery