Adding die();
to the end of my ajax function file gives me totally blank page and this error in Firebug:
The character encoding of the HTML document was not declared. The document will render with garbled text in some browser configurations if the document contains characters from outside the US-ASCII range. The character encoding of the page must to be declared in the document or in the transfer protocol.
I scaled down to a very basic ajax function file:
<?php
function show_article(){
$q = $_GET['getid'];
echo strval($q);
}
die();
?>
Which still gives the empty page and error. Without die();
at the close, it works as expected but with the extra 0 at the end of the echoed $q value.
I'm not sure what is causing this issue. For extra context, here's what I've got in my functions.php file.
function ajaxscripts() {
wp_enqueue_script( 'productajax', get_template_directory_uri().'/js/productajax.js', false, null, false );
wp_localize_script( 'productajax', 'myajax', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) );
}
add_action('wp_enqueue_scripts', 'ajaxscripts');
$dirName = dirname(__FILE__);
$baseName = basename(realpath($dirName));
require_once ("$dirName/getarticle.php"); //my ajax function file
add_action( 'wp_ajax_nopriv_show_article', 'show_article' );
add_action( 'wp_ajax_show_article', 'show_article' );