• Hey there,

    I’m sending two AJAX requests from one page using admin-ajax.php. The first when the user clicks one element, the second when they click on the next, and it always happens in that order. I absolutely cannot get the second request to work – it fails without a hint of what’s wrong.

    The request returns this in Firebug (Firefox): https://cl.ly/1w5u
    And this in Webkit inspector: https://cl.ly/1wYn

    Here’s the JS that fires the second request:

    jQuery('.cropimage').click(function(){
    	var pid = jQuery('#tump_header_img').val();
    	var path = jQuery('#header_img_edit .container img').attr('src');
    	var dimensions = jQuery('#tump_header_img_position').val();
    	var security = jQuery('#_ajax_nonce_crop_header_image').val();
    	var data = {
    		pid: pid,
    		action: 'crop_header_image',
    		path: path,
    		dimensions: dimensions,
    		security: security
    	};
    	jQuery.post(ajaxurl, data, function(response) {
    		console.log(response);
    	});
    });

    And the PHP (functions.php):

    add_action('wp_ajax_crop_header_image', 'crop_header_image');
    
    function crop_header_image() {
    	check_ajax_referer('crop_header_image', 'security'); 
    
    	$data = $_POST;
    	unset($data['security'], $data['action']);
    
    	$dimensions = explode(',',$data['dimensions']);
    
    	$extension_pos = strrpos($data['path'], '/'); // find position of the last dot, so where the extension starts
    	$newpath = substr($data['path'], 0, ($extension_pos +1)) . 'cropped-' . substr($data['path'], ($extension_pos + 1));
    
    	update_option( 'tump_header_img_path', $newpath );
    
    	die( wp_crop_image($data['pid'],$dimensions[0],$dimensions[1],$dimensions[2],$dimensions[3],940,200) );
    }

    The other requested is composed exactly the same way, I’ve gone through it dozens of times. I can’t figure out why I’m not able to get any sort of response or error code.

    If you’d like any other information, please do ask, and thank you in advance for any help you an offer!

  • The topic ‘admin-ajax.php Not Responding to Second Request’ is closed to new replies.