I'm creating a wordpress plugin and I use the wp_ajax_[your action] callback. In my code the php return nothing to the javascript (no echo, no return). If the php return no value, the 'data' in 'success: function(data)' is empty so why the 'click' trigger work?
the js:
$(document).one('click', '#publish', function (event) {
event.preventDefault();
jQuery.ajax({
type:"post",
url: ajaxurl,
data: {action: 'save_img_data', imgUrlsArray: iUrlsArray, imgNamesArray: iNamesArray, pid: pl_vars.post_id},
success: function(data) {
$('#publish').trigger( "click" );
}
});
});
the php:
function lmg29_img_data() {
$pid = $_POST['pid'];
$iUrlsArray = $_POST['imgUrlsArray'];
$iNamesArray = $_POST['imgNamesArray'];
if (isset($iUrlsArray) and isset($iNamesArray)) {
update_post_meta( $pid, 'lg29_urls', $iUrlsArray );
update_post_meta( $pid, 'lg29_names', $iNamesArray );
die();
}
}
add_action("wp_ajax_save_img_data", "lmg29_img_data");
as you can see there's no response: