Wordpress/Buddypressで簡単なAjaxテストをしようとしています。Wordpress Ajax Firefox応答がありません
下記のコードは、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";
}
誰かが保存されますそれは**キー**でした。ありがとう! – Arsalan
よろしくお願い致します!新しいajax + wordpressをやっていて、このデフが私にある時間を節約しました:) –