1

ajax 呼び出しから何も返されない (0 を返す) 理由がわかりません。私がやろうとしているのは、ユーザーがフォームに LAN ID を入力すると、スーパーバイザーの情報がいくつかのフィールドに自動的に入力されることです。どんな助け/提案も大歓迎です。これが私のコードです:

add_action('wp_ajax_nopriv_get_ldapattr', 'get_ldap_attr');

jQuery(関数() {

jQuery('#empLanId').on('blur', function() {

    var lanid = jQuery('#empLanId').val(),
        data = { action: "get_ldap_attr", lanid: lanid };

        jQuery.ajax({
            url: ajaxurl,
            dataType: 'json',
            data: data,
            success: function(response) {
                console.log(response);
            },
            error: function() {
                console.log('error');
            }

        });

});

});

関数 get_ldap_attr($lanid) {

$dn = get_site_option ( "ldapServerOU" );
$usr = get_site_option ( "ldapServerCN" );
$pw = get_site_option ( "ldapServerPass" );
$addr = get_site_option ( "ldapServerAddr" );
$ids = array();
$ad = ldap_connect ( $addr )
    or die ( "Connection error." );
ldap_set_option ( $ad, LDAP_OPT_PROTOCOL_VERSION, 3 );
ldap_set_option ( $ad, LDAP_OPT_REFERRALS, 0 );
$bind = ldap_bind ( $ad, $usr, $pw );

if ( $bind ) {
    $SearchFor ="cn=".$lanid;
        $result = ldap_search ( $ad,$dn,$SearchFor );

        $entry = ldap_first_entry ( $ad, $result );
        if ( $entry != false )  {
            $info = ldap_get_attributes ( $ad, $entry );
        }
        $comm  = stripos ( $info['directReports'], ',' );
            // find position of first comma in CN=Mxxxxxx,OU=Users,OU=MCR,DC=mfad,DC=mfroot,DC=org  (directReports field)
        $eq = stripos ( $info['directReports'], '=' );
            // find position of first =
        $s_lanid = substr ( $info['directReports'], $eq+1, ( ( $comm-1 ) - ( $eq ) ) );
            //get substring between = and comma... for lanid happiness..
        $sup = getLDAP ( $s_lanid, $ad, $dn, $usr, $pw );
            // get supervisor's info...
}

//return $sup;

echo json_encode($sup); die();
4

4 に答える 4

1

あなたが書くなら

add_action('wp_ajax_nopriv_**get_ldapattr**', '**get_ldap_attr**');

だからあなたは電話する必要がありget_ldapattrますget_ldap_att

つまり指定すると

add_action('wp_ajax_nopriv_**ACTION_HANDLER**', '**CALLBACK_FUNCTION**');

ACTION_HANDLERajax jsスクリプトを呼び出す必要があります(ACTION_HANDLERと一致しない限りCALLBACK_FUNCTION

于 2014-10-28T10:18:51.423 に答える