gpt4 book ai didi

javascript - 对事件目录进行 ajax 调用并使用 post 提取缩略图照片

转载 作者:可可西里 更新时间:2023-11-01 01:50:44 25 4
gpt4 key购买 nike

我想使用 post 从事件目录中检索信息(例如缩略图照片)。

<?php
/**
* Get a list of users from Active Directory.
*/
$ldap_password = $_POST['password'];
$ldap_username = $_POST['username'];
$server = 'ldap://xxxxxxxxxxxxxxxxxxxxxx';
$domain = 'xxxxxxxxxxxxxxxxx';
$port = 389;
$ldap_connection = ldap_connect($server, $port);

if (FALSE === $ldap_connection){
// Uh-oh, something is wrong...
}

// We have to set this option for the version of Active Directory we are using.
ldap_set_option($ldap_connection, LDAP_OPT_PROTOCOL_VERSION, 3) or die('Unable to set LDAP protocol version');
ldap_set_option($ldap_connection, LDAP_OPT_REFERRALS, 0); // We need this for doing an LDAP search.

if (TRUE === ldap_bind($ldap_connection, $ldap_username.$domain, $ldap_password)){
$ldap_base_dn = "OU=Employees,OU=Accounts,OU=xxxxx,DC=xxxxxx,DC=xxxxxxx,DC=com";
$search_filter = '(&(objectCategory=person)(samaccountname=*))';
$attributes = array();
$attributes[] = 'givenname';
$attributes[] = 'mail';
$attributes[] = 'samaccountname';
$attributes[] = 'sn';
$result = ldap_search($ldap_connection, $ldap_base_dn, $search_filter, $attributes);
$maxPageSize = 1000;
if (FALSE !== $result){
$entries = ldap_get_entries($ldap_connection, $result);
for ($x=0; $x<$entries['count']; $x++){
if (!empty($entries[$x]['givenname'][0]) &&
!empty($entries[$x]['mail'][0]) &&
!empty($entries[$x]['samaccountname'][0]) &&
!empty($entries[$x]['sn'][0]) &&
'Shop' !== $entries[$x]['sn'][0] &&
'Account' !== $entries[$x]['sn'][0]){
$ad_users[strtoupper(trim($entries[$x]['samaccountname'][0]))] = array('email' => strtolower(trim($entries[$x]['mail'][0])),'first_name' => trim($entries[$x]['givenname'][0]),'last_name' => trim($entries[$x]['sn'][0]));
}
}
}
ldap_unbind($ldap_connection); // Clean up after ourselves.
}

$message .= "Retrieved ". count($ad_users) ." Active Directory users\n";
?>

我尝试使用 http://localhost:8666/web1/activedirectory.php 查看它是否返回任何内容,但它返回以下错误,因为结果为 >1000。

Warning: ldap_search(): Partial search results returned: Sizelimit exceeded in C:\xampp\htdocs\web1\activedirectory.php on line 28

Notice: Undefined variable: message in C:\xampp\htdocs\web1\activedirectory.php on line 46

下面是我想将 .php 文件链接到上面文件的 jquery:

$('.leaderboard li').on('click', function () {
$.ajax({
url: "../popupData/activedirectory.php", // php file with link to the active directory.
type: "POST",
data: {id:$(this).find('.parent-div').data('id')},
success: function(data){
console.log(data);
data = JSON.parse(data);
$('#popup').fadeIn();
//call for the thumbnail photo
// etc ..
},
error: function(){
alert('failed, possible script does not exist');
}
});
});

最佳答案

第一个问题:

你必须附加一个 img 元素而不是像这样设置文本:

$('#imagesofBadges').append('<img src="'  + data[0].BadgeImage + '"/>');

第二个问题:

在附加图像时添加一个类属性,这样您就可以使用类名使用 jQuery 获取它们,如下所示:

var $img = $('<img src="'  + data[0].BadgeImage + '"/>'); // create the image
$img.addClass('badge-image'); // add the class .badge-image to it
$('#imagesofBadges').append($img); // append it

现在您可以像这样使用选择器获取这些图像:

$('#imagesofBadges .badge-image'); // will fetch all the elements that have the class .badge-image that are inside #imagesofBadges.

编辑:

如果您想在添加新图像之前删除 #imagesofBadges 中的所有图像,请使用此命令:

// fetch all the images inside #imagesofBadges and remove them
$('#imagesofBadges img').remove();
// append the new image
$('#imagesofBadges').append('<img src="' + data[0].BadgeImage + '"/>');

关于javascript - 对事件目录进行 ajax 调用并使用 post 提取缩略图照片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41829087/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com