I use WordPress, PHP, jQuery and AJAX.
I can get data from PHP through an AJAX call, like this:
$.ajax({
type: "POST",
url: "<?php echo get_bloginfo('url'); ?>/?addmod_ajax=1",
data: "action=load&type=part",
success: function(data){
alert(data);
}
});
When I have received the data I also want to know how it went. The “data” contains HTML and I also want error codes like “success” or “not-found”.
How do I solve it the best way?
WordPress
Because I use WordPress I need to call a AJAX trigger (in the url). If I could keep that intact it would be nice.
You could add a failure handler to see if the ajax request is failed, but other than that, if want a different return value, you will have to change the result of the function you are calling on the backend, or create a new similar function that instead of just returning the html, returns a json encoded array with the first element being found or not found, and the second element being the html.
Edit: Appended comment to complete answer and format code.
at the place where you echo ‘your result’, you can echo instead
and in your ajax call, add
then you can access the success and html values in your success handler.