0

I have been able to fetch data with an ajax call from active directory .

The php file used to make the ajax call to active directory: http://pastebin.com/5VMPU6wp

The browser console shows that an ajax call returns this:

   <p> sn: xxxxxx<br/>givenname: xxxxx<br/>
   employeeID: 0050<br/
   >distinguishedName: CN=xxxx     xxxxx,OU=Employees,OU=Accounts,OU=India,DC=asia,DC=xxxxxxx,DC=com<br/>
   displayName: Mark Hewettk<br/>sAMAccountName: xxxxxxx<br/>
   department: xxxxx<br/>manager: CN=xxxxxx xxxxxxx,OU=Employees,OU=Accounts,OU=India,DC=asia,DC=xxxx,DC=com
   <br/>
   mail: mhewettk@abc.com<br/>
   title: xyz<br/>
   photo :����%&'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz���������������������������������������������������������������������������

The problem is that I am unable to display the thumbnail photo i.e the photo tag above.

I want to display the photo in a html popup window :

<img src="data:image/jpeg;base64,<?php echo base64_encode($data['thumbnailPhoto'][0]); ?>"alt="Please Upload your display pic." width="200" height="200" class="profile__image" id ="popupPic" />

I am able to display other attributes from the console such as title ,mail ,department etc by calling the jQuery as follows :

 $('.leaderboard li').on('click', function () {
 $.ajax({
 url: "../popupData/activedirectory.php", 
 type: "POST",
 data: {id:$(this).find('.parent-div').data('id')},
 success: function(data){
 console.info(data);
 $('#popup').fadeIn();
 var email=(data.split("mail:")[1]).split("title:")[0];
 $('#emailOfUser').html('Email:'+ email); 
 var dept=(data.split("department:")[1]).split("manager:")[0];
 $('#departmentOfUser').html('Department:'+ dept);
 var pic=(data.split("photo:")[1]).split("manager:")[0];
 $('#popupPic').append(pic);
 },
 error: function(){
 alert('failed, possible script does not exist');
 }
 });
 });

I tried this jQuery but no luck.

var pic=(data.split("photo:")[1]).split("manager:")[0];
$('#popupPic').append(pic);

This link from the community also did not help: Display thumbnailPhoto from Active Directory in PHP

How to display the photo from the above console data i.e the data retrieved from the ajax call?

Community
  • 1
  • 1
JAne
  • 97
  • 1
  • 10
  • you need to do something like this `document.getElementById("popupPic").src = data:image/png;base64," + pic;` here pic is the variable in which your image bytes are stored – Minksmnm Jan 31 '17 at 11:04
  • @Minksmnm thanks for the input.How will the html of tag look like here . – JAne Jan 31 '17 at 11:20
  • in the jquery code you are using `$('#popupPic').append(pic)` , replace this with `document.getElementById("popupPic").src = data:image/png;base64," + pic;` i am not confirm but seems like this should work – Minksmnm Jan 31 '17 at 11:24
  • First of all, you should start by making the server-side script return a proper data structure (JSON ), instead of chunks of text separated by BR elements. That will make processing the data on the client side much easier. – CBroe Jan 31 '17 at 12:57

0 Answers0