Using ajax and wordpress (trying to do it right). This is new to me, but I worked with him even more. It seemed that I was having problems, so I broke my code to the most basic level, and I can’t even make it work !!! I feel like I'm just upset, and it makes me miss a simple mistake. Is there something wrong with this?
My jQuery:
$.post(
ajaxurl,
{action: "post-save"},
function(response){
alert(response);
}
);
My PHP:
function update_post(){
echo json_encode(array("success" => "all systems go"), JSON_FORCE_OBJECT );
exit;
}
add_action( 'wp_ajax_post-save', 'update_post' );
The end result is an alert, which means $ .post is successful (right?), But the returned variable responseis the html source of my home page ...
jamil source
share