2013-08-02 50 views
0

我有問題的Wordpress總是返回0在這個Ajax調用。誰能告訴我我做錯了什麼?Wordpress返回0在AJAX調用

阿賈克斯:

$j.ajax({ 
     type: 'POST', 
     url: 'http://localhost/all-in-one/wp-admin/admin-ajax.php', 
     data: { 
     action: 'header_galley_ajax', 
     id: '1' 
     }, 
     success: function(data, textStatus, XMLHttpRequest){ 
     alert (data); 
     }, 
    error: function(MLHttpRequest, textStatus, errorThrown){ 
     alert('error:'+errorThrown); 
    } 
    }); 

的functions.php:

function header_galley_ajax() { 
    $id = $_POST['id']; 
    echo "ajax fired:".$id; 
    die(); 
} 
add_action('wp_ajax_nopriv_ header_galley_ajax', 'header_galley_ajax'); 
add_action('wp_ajax_ header_galley_ajax', 'header_galley_ajax'); 
+0

只注意到白add_actions中的空格。解決了 –

回答

1

您需要刪除 'wp_ajax_nopriv_ header_galley_ajax' 和 'wp_ajax_ header_galley_ajax' 空間:

add_action('wp_ajax_nopriv_header_galley_ajax', 'header_galley_ajax'); 
add_action('wp_ajax_header_galley_ajax', 'header_galley_ajax');