Site icon Hip-Hop Website Design and Development

AJAX Post from same domain to a wordpress page

I am trying to create an ajax post listener to a wordpress page in a domain (let’s just say http://example.com). Another web app in the same domain (http://example.com) exists and a user sends ajax posts from there.

I have implemented a simple page:

<?php
get_header();
?>
<h3>Listener</h3>
<div id="listener1">
</div>
<script type="text/javascript">
jQuery(document).ready(function($){
    console.log("Into WPTOASTER");
    $.ajaxSetup({
        success: function() {
            console.log("trapped?");
        }
    });
});
</script>
<?php
get_footer();
?>

that is located to http://example.com/listener .

In the same server, I have an http://example.com/zzz.php which has the following code:

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<script type='text/javascript' src='http://example.com/wp-includes/js/jquery/jquery.js?ver=1.11.3'></script>
<script type='text/javascript' src='http://example.com/wp-includes/js/jquery/jquery-migrate.min.js?ver=1.2.1'></script>
</head>
<body>
<form name="aaaa">
<input type="hidden" name="aaa" value="111">
<button type="button" id="salty">CLICK AND SUBMIT</button>
</form>
<script>
jQuery(document).ready(function($){
    $(document).on("click","#salty",function(ev){
        ev.preventDefault();
        $.post('http://example.com/listener',{"name":"john","lastname":"smith"},function(data){
            console.log("check if sent.");
        });
    });
});
</script>
</body>
</html>

When I use zzz.php to send ajax requests to listener I get a 404 error. The operation would be a simple notification once the php is received. Can anyone help me on this?