jquery - Ajax with WordPress Functions.php always returns 0 -


i know question has been asked lot, apologize redundancy. however, can not seem make return value other 0. below code have included @ bottom of functions.php within twenty-twelve theme:

add_filter( 'views_edit-destination', 'so_13813805_add_button_to_views' ); function so_13813805_add_button_to_views( $views ) {     $views['my-button'] = '<button id="update-dest-cache" type="button" class="button"             title="update destinations cache" style="margin:5px" onclick="updatedestcache()">update destinations cache</button>';     $views['my-button'] .= '         <script type="text/javascript" >         function updatedestcache() {             jquery.ajax({                 type: "post",                 url: ajaxurl,                 datatype: "json",                 action: "testajaxfunction",                 success: function(response){                      alert("got server: " + response);                 },                 error: function(mlhttprequest, textstatus, errorthrown){                       alert("there error: " + errorthrown);                   },                 timeout: 60000             });             };         </script>     ';     return $views; } function testajax(){     echo "anything!!!!";     die(); } add_action('wp_ajax_testajaxfunction', 'testajax'); add_action('wp_ajax_nopriv_testajaxfunction', 'testajax' ); 

this code adds button edit list of custom post type, , runs function upon click. button shows up, function runs, ajax function called, 0 response.

any thoughts on why continues occur?

i had javascript written incorrectly.

function updatedestcache() {    jquery.ajax({       type: "post",       url: ajaxurl,        data: { action: "testajaxfunction" }, <---- line changed       success: function(response){           alert("got server: " + response);       },       error: function(mlhttprequest, textstatus, errorthrown){            alert("there error: " + errorthrown);         },       timeout: 60000    });     }; 

Comments

Popular posts from this blog

Unable to remove the www from url on https using .htaccess -