Note that there are some explanatory texts on larger screens.

plurals
  1. POWordPress - Ajax Request Keeps Returning 0
    text
    copied!<p>I can't seem to figure out why nothing is returned from my ajax call (returns a 0). What I'm trying to do is when a user fills out their LAN ID on a form, their supervisor's information auto populates a few fields. Any help/suggestions is much appreciated. Here's my code:</p> <p>add_action('wp_ajax_nopriv_get_ldapattr', 'get_ldap_attr');</p> <p>jQuery(function() {</p> <pre><code>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'); } }); }); </code></pre> <p>});</p> <p>function get_ldap_attr($lanid) {</p> <pre><code>$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(); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload