• Hi everybody.
    I apologize for my being little more han a newbie in WP and ajax but I need your help. I’m not sure if it’s a bug or it’s simply me who cannot manage to find a solution.
    I’ve the following situation.
    I’ve a plugin that displays certain data from a remote mysql server. This data need to be updated periodically.
    At the moment I’ve implemented this through AJAX, more or less, like this:

    $.ajax({
    	type : "POST",
    	url: cktn_ajax_object.ajax_url,
    	data: params,
    	dataType: "json",
            success: function(response) {
    		<< Update  UI according to response>>
    	},
    	error: function(request, status, err) {
    		console.debug("[AjaxOnTimer Error] status: " + status);
    	}
    });

    where $.ajax is calling the relevant php script responsible for retrieving the remote mysql data. The PHP script duration is variable, according to the amount of data it fetches (Let’s say, something between a few seconds and four or five minutes).
    If I test the whole on my local machine, there is no problem. The ajax call duly and patiently awaits the (slow) response of the *local* PHP server (which is querying the *remote* mysql server) and eventually, upon completion, it updates my UI.
    On the other hand, when I install my plugin on the production machine things don’t work as expected. Just a few seconds after having placed my ajax call to the PHP server, i get the following error in the console of the browser: “Failed to load resource: connection lost. —> admin-ajax.php” and my script fails leaving me no other clue than the word “error” in the ‘status’ parameter of the ajax call.
    Apparently the heartbeat.lock-post is interfering with my ajax call.
    Any idea of what am I doing wrong?

Viewing 1 replies (of 1 total)
  • Thread Starter caraffande

    (@caraffande)

    I’ve tested further. The problem seems to be an admin-ajax time-out related problem.
    I’ve disabled the ‘heartbeat’ script using this

    public function on_init() {
    		wp_deregister_script('heartbeat');
    	}
    
    	public function __construct()
    	{
    		add_action('init', array( $this, 'on_init'));

    and now my ajax script awaits longer. But the problem now is the autosave.
    When the autosave event is fired, the connection timeouts and my script is gone once again.
    Apparently, each admin-ajax call made (by WP) while my script is running, breaks my script. How can I keep the two “worlds”, WP ajax calls and my plugin’s ones, separated?

Viewing 1 replies (of 1 total)
  • The topic ‘admin-ajax: Failed to load resources: connection lost’ is closed to new replies.