我的 AJAX 调用在 Chrome 中运行良好,但是当我在 Firefox 或 IE 中对其进行测试时,我收到一个空响应。任何帮助深表感谢!
我的 PHP 函数:
function get_ldap_attr() {
$lan = $_POST['lan'];
$dn = get_site_option ( "ldapServerOU" );
$usr = get_site_option ( "ldapServerCN" );
$pw = get_site_option ( "ldapServerPass" );
$addr = get_site_option ( "ldapServerAddr" );
$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=".$lan;
$result = ldap_search ( $ad,$dn,$SearchFor );
$entry = ldap_first_entry ( $ad, $result );
if ( $entry != false ) {
$info = ldap_get_attributes ( $ad, $entry );
}
$comm = stripos ( $info['manager'][0], ',' );
// find position of first comma in CN=Mxxxxxx,OU=Users,OU=MCR,DC=mfad,DC=mfroot,DC=org (directReports field)
$eq = stripos ( $info['manager'][0], '=' );
// find position of first =
$s_lanid = substr ( $info['manager'][0], $eq+1, ( ( $comm-1 ) - ( $eq ) ) );
//get substring between = and comma...
$sup = getLDAPInfo ( $s_lanid, $bind, $ad, $dn );
// get supervisor's info...
$subInfo = getLDAPInfo ($lan, $bind, $ad, $dn);
}
echo json_encode( array( $sup, $subInfo ) );
die();
}
我的 jQuery:
jQuery(function() {
jQuery('#empLanId').on('blur', function() {
var lan = jQuery('#empLanId').val(),
data = { action: "get_ldap", lan: lan};
jQuery.ajax({
type: 'POST',
url: ajaxurl,
data: data,
dataType: 'json',
success: function(response) {
console.dir(response);
jQuery('#empName').val(response[1].fullname);
jQuery('#empSupLanId').val(response[0].lanid);
jQuery('#empSupName').val(response[1].fullname);
jQuery('#empSupNumber').val(response[1].phone);
}
});
});
});