Я не могу понять, почему ничего не возвращается из моего вызова ajax (возвращает 0). То, что я пытаюсь сделать, - это когда пользователь заполняет свой ЛВС-идентификатор в форме, а информация его супервизора заполняет несколько полей. Любая помощь/предложения очень ценится. Вот мой код:WordPress - Ajax Request Keeps Returning 0
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();
Если Вы заканчиваете с 'фильеры (json_encode (массив ('тест' => 'значение')))' делает консоль показывает, что массив? Утверждение, что ваша переменная '$ sup' не является проблемой. – jterry
Все еще возвращает 0. – Shapada
Даже если вы _start_ 'get_ldap_attr()' с этим? – jterry