Ajax call to php function doesn’t work PHP code

It looks like the MBAjax.ajaxurl and MBAjax.admin_url are probably not set. If it can’t post to the correct WordPress handler, then you will probably get a 404 page HTML returned instead of the PHP function return value.

You can test by hard-coding the ajax url to url: "/wp-admin/admin-ajax.php", and see if that fixes things.

Secondly, I have always added a hidden field on my forms with the action <input type="hidden" name="action" value="make_booking">

Try that and see how you get on. Also check your browser console network tab to see the AJAX request being sent. You can check the data you are POSTing and also the response you get back. Easier than trying to use alerts.

enter image description here

You can also use console.log(x) instead.

Update: I think you’re missing sending anything in your AJAX request:

jQuery.ajax({
   action : 'make_booking',
   type   : "POST",
   data   : {
      action: 'make_booking'
   }
   url    : MBAjax.admin_url,
   success: function(data) {
      alert(data);
      //jQuery("#container" ).append(data);
   },
   fail: function(error){
      alert("error" + error);
   }
});

Try that.