Wordpress/Buddypress에서 간단한 ajax 테스트를 시도하고 있습니다.Wordpress Ajax Firefox 응답 없음
아래 코드는 IE와 Chrome에서 잘 작동합니다. Firefox에서는 자바 스크립트가 호출되었지만 현재 페이지가 새로 고침됩니다. 방화 켓 콘솔에 오류가 없지만 응답이 비어 있습니다. PHP가 호출되고 있다고 생각하지 않습니다.
Firefox에서이 기능을 사용하려면 무엇을 변경해야합니까?
자바 스크립트 :
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는 :
이 FF, 크롬과 IE에서 작동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";
}
는 "로그인되어 있지 않을 경우, 후크 wp_ajax_nopriv_myfunction를 호출 wp_ajax." 그것은 ** 열쇠 **였습니다. 고마워요! – Arsalan
감사합니다. 새로운 아약스 + wordpress 하고이 데프 나를 좀 시간을 절약 :) –