Я пробую простой ajax-тест в Wordpress / Buddypress.
Приведенный ниже код отлично работает в IE и Chrome.Но в Firefox вызывается javascript, но затем он просто обновляет текущую страницу.В консоли firebug нет ошибок, но ответ пуст.Я не думаю, что php вызывается.
Что мне нужно изменить, чтобы это работало в Firefox?
JavaScript:
jQuery(document).ready(function(){
jQuery('#test-form input#save').click(function(){
jQuery('.ajax-loader').toggle();
jQuery('#save').attr({'disabled': true});
jQuery.post( ajaxurl, {
action: 'test_save',
'cookie': encodeURIComponent(document.cookie),
'_wpnonce': jQuery("input#_wpnonce-save").val(),
},
function(response) {
jQuery('.ajax-loader').toggle();
// alerts work up to here in all browsers
jQuery('#test-form').append(response);
});
});
});
php:
add_action( 'bp_after_profile_loop_content', 'show_test', 100 );
add_action('wp_ajax_test_save', 'test_save_function');
function show_test() {
?>
<form action="#" id="test-form">
<?php wp_nonce_field( 'save', '_wpnonce-save' ); ?>
<input type="submit" name="save" id="save" value = "test ajax"/>
<span class="ajax-loader"></span>
</form>
<?php
}
function test_save_function() {
check_ajax_referer('save');
echo "php -button was clicked";
}