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/tSRxwQL8
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/>
I want to take only some attributes above like mail,displayname etc and display in my HTML :
<h2 class="profile__name" id="emailOfUser">Email : </h2>
Now the problem is the jquery that I have used here :
$('.leaderboard li').on('click', function() {
$.ajax({
url: "../popupData/activedirectory.php", // your script above a little adjusted
type: "POST",
data: {
id: $(this).find('.parent-div').data('name')
},
success: function(data) {
console.log(data);
$('#popup').fadeIn();
$('#emailOfUser').html(data); //this line displays all data whereas I want to select only email,displayname from the above console data
//whatever you want to fetch ......
// etc ..
},
error: function() {
alert('failed, possible script does not exist');
}
});
});
problem is this :
$('#emailOfUser').html(data);
this line displays all data whereas I want to select only email,displayname from the above console data
kindly help me how to select only desired attribute data from the above browser console data.
Ideally you should return JSON from PHP file, however if it is not possible for you to make changes to PHP file then you can use split("mail:") and split("title:") to extract data
success: function(data) {
console.log(data);
$('#popup').fadeIn();
var email=(data.split("mail:")[1]).split("title:")[0];
$('#emailOfUser').html(email); //this line displays all data whereas I want to select only email,displayname from the above console data
//whatever you want to fetch ......
// etc ..
},
You are getting response in HTML which makes difficult for you to extract mail, displayname, etc.
You should get the response in JSON which will make it easy for you to extract the required info.
Ask your back-end team to send response in JSON format.
Working Fiddle
Try :
var lines = 'sn: xxxxxx<br/>givenname: xxxxx<br/>employeeID: 0050<br/>distinguishedName: CN=xxxxxxxxx,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/>'.split('<br/>');
jQuery.each(lines, function() {
var val = this;
if (val.indexOf('mail') > -1)
// alert(val.split(':')[1]); //Only for test
$('#emailOfUser').html(val.split(':')[1]);
});
Related
This is my layout
I want to update in relativaly "real-time" let's say every 10 seconds or so... the badge that says approved will say the getStatus()
My problem is that i need to fetch data from a List and I have no idea how to send all this data to the JavaScript file.
runningContainers is a List and i need to get runningContainers.getName() and runningContainer.getStatus() for every one in the list and send it to the javascript.
I just need a way to pass all the data to the javascript so I can update the badges relativally to that name.
Java
try {
DockerClientConfig config = DefaultDockerClientConfig.createDefaultConfigBuilder()
.withDockerHost("tcp://localhost:2375")
.withDockerConfig("/")
//.withRegistryUsername("profile")
//.withRegistryPassword("profile")
.build();
DockerClient dockerClient = DockerClientBuilder.getInstance(config).build();
List<Container> runningContainers = dockerClient.listContainersCmd()
.exec();
JavaScript
$.ajax({
type: 'post',
url: 'Containers',
success: function () {
},
error: function() {
}
});
});
This is my first post. I have searched for other solutions and what I've found only deals with components of this question. Basically this is what I'd like to do:
Capture form data (tested, working);
Convert form data using serializeArray() or serialize() (tested both options, working and outputs to console correctly);
Send this information to the server through Ajax (not working); and
PHP saves array as a CSV (not yet started).
Bellow is the code I'm using. But first, here are some alternatives I've tried. Usually I get this: array(0) { }
'dataType' as Json - returns error;
'GET', 'POST' and 'REQUEST' - PHP shows empty array;
use form.serialize() - PHP shows empty array;
use form.serializeArray() - PHP shows empty array; and
var_dump($_POST), var_dump($_GET), var_dump($_REQUEST).
var serialisedForm = $(form).serializeArray();
var serialisedData = JSON.stringify(serialisedForm);
console.log(serialisedData); //working
console.log(serialisedForm); //working
$.ajax({
type: "POST",
url: "datacapture.php",
data: {
serialisedForm, //tested using serialisedData as well
},
success: function() {
window.open('datacapture.php');
},
error: function() {
alert("the form data has not been sent to the server");
}
})
and here is the datacapture.php script I'm using to test the information flow.
<?php
var_dump($_POST);
?>
EDIT - and here is a sample form item, reading .text and .name from my settings.json file:
<tbody>
{
this.props.settings.schemes[0].questions.map((q, i)=> {
return <tr><td>{q.text}</td><td><div class="YesNo"><input type="radio" required name={q.name} value="yes">Yes</input><input type="radio" required name={q.name} value="no">No</input></div></td></tr>
})
}
</tbody>
just change 1seralisedForm1 to 1seralisedData1 it will return an json object to php which can be seen by doing:
echo json_decode($_POST);
$('#data').change(function () {
$.ajax({
url: 'richiesta.php',
type: 'POST',
dataType: 'json',
data: {
value: this.value
},
}).done(function (data) {
$('#textfield').val(JSON.stringify(data));
$('#results').val('Descrizione codice: ' + data[0].descrizione_codice);
});
});
richiesta.php is just a file that triggers some functions to get the JSON.
#textfield is correctly populated with the raw JSON, so everything is working properly.
I can't figure out how to output the first item of the JSON identified by the name descrizione_codice in #results.
The JSON is valid, here's an example selecting one option (truncated):
{
"data":[
{
"codice_comparto":"PRO",
"descrizione_codice":"Competenze fisse per il personale a tempo indeterminato",
"codice_siope":"1101",
"descrizione_ente":"",
"ricerca":false,
"idtable":"000717409-1101",
"cod_ente":"000717409",
"anno":"2014",
"periodo":"12",
"codice_gestionale":"1101",
"imp_uscite_att":"756",
"importo_2013":"37718576",
"importo_2014":"32810124",
"importo_2015":null
}
],
"cosa":false
}
I'm doing something wrong is that data(0).descrizione_codice as Firebug tells me "data is not a function"..
I'm not using $.parseJSON because jQuery already parses data correctly thanks to the datatype.
I put up a test page here. You can request the JSON response selecting an option from the dropdown menu.
According to your JSON structure you should be able to access array as data.data
.done(function (data) {
console.log(data.data[0].descrizione_codice);
});
$('#results').val('Descrizione codice: ' + data.data[0].descrizione_codice);
First data is your actual js variable
Second data is your array inside JSON named "data" where we access first element's property named "descrizione_codice"
Hope it clarifies
What I want to do:
I want to do a input text field with a jquery autocomplete function which gets the source data from a cross-domain curl request. The result should look similar like this: http://abload.de/img/jquerydblf5.png (So I actually want to show additional infos which I get from the curl Request). The URL to get the source data is http://www.futhead.com/15/players/search/quick/?term= and in the end I add those letters which are currently typed in at my input field (for example "Ronaldo").
At the moment I only tried to perform the searchrequest without showing all infosin the dropdown as shown in the screen above. I only want to see which playernames I actually got back by the curl request. Later I will try to add more information for the dropdown. Maybe you guys can help me as well with this as well (I think its called custom renderItem ??).
This is what I've tried:
<script>
$( "#tags" ).autocomplete({
source: function (request, response) {
$.ajax({
type: 'GET',
url: 'playerscraper.php',
dataType: "json",
data: function () {
return $("#results").val()
},
success: function (data) {
// I have no idea what this response and map is good for
response($.map(data, function (item) {
return {
label: item.label,
id: item.value,
};
}));
},
});
}
});
</script>
<div class="ui-widget">
<label for="tags">Tags: </label>
<input id="tags">
</div>
My playerscraper.php is performing the curl request and actually returns a array (tested with echo):
$term = $_GET['term'];
$curlRequest = new CurlRequest();
$result = $curlRequest->get('http://www.futhead.com/15/players/search/quick/?term=' . $searchterm);
$players = array();
return json_encode($result);
My problem:
I have no idea how to do the source part for the autocomplete function this way, that I get the right results from the ajax request with my searchterm from the input field. When I type in something in the input field, nothing happens (the function which defines the source is getting called - tested with an alert).
I m validating email id in php and ajax, and want to return value from php page to html in JSON format.
I want to keep that return value in php variable for the further use.
I'm doing these all in codeigniter, and I want to show .gif image while my AJAX is processing. (Pre loader image)
AJAX/Javascript/jQuery:
function checkEmail(value_email_mobile) {
if (value_email_mobile !== '') {
//alert('te');
$.ajax({
type: "POST",
url: url_check_user_avail_status,
data: "value_email_mobile=" + value_email_mobile,
success: function(msg) {
alert(msg);
//$('#psid').html("<img src='images/spacer.gif'>");
// $('#stat').html(msg);
//
//$('#sid').sSelect({ddMaxHeight: '300px'});
},
error: function() {
//alert('some error has occured...');
},
start: function() {
//alert('ajax has been started...');
}
});
}
}
PHP/Controller:
<?php
function check_email_or_mobile($param)
{
$ci = CI();
$value = $param['email_or_mobile'];
$query = "SELECT user_email , mobile FROM tb_users WHERE user_email = '$value' or mobile = '$value'";
$query = $ci->db->query($query);
if ($query->num_rows() > 0)
{
if (is_numeric($value))
{
return $res = "This mobile number is not registerd";
}
else
{
return $res = "This Email id is not registerd";
}
}
}
This is just to give you an example on how it will work.
First off, (obviously) there must the a preloader image ready inside the document. This must be hidden initially.
Second, before triggering the AJAX request, show the loading animated GIF.
Third, after the request if successful. Hide the image again inside your success: block inside the $.ajax().
Consider this example: Sample Output
PHP:
function check_email_or_mobile($param) {
// your functions, processes, blah blah
// lets say your processes and functions takes time
// lets emulate the processing by using sleep :)
sleep(3); // THIS IS JUST AN EXAMPLE! If your processing really takes time
$data['message'] = 'Process finished!';
// with regarding to storing, use sessions $_SESSION for further use
$_SESSION['your_data'] = $data_that_you_got;
echo json_encode($data); // use this function
exit;
}
// just a simple trigger for that post request (only used in this example)
// you really dont need this since you will access it thru your url
// domain/controller/method
if(isset($_POST['request'])) {
check_email_or_mobile(1);
}
HTML/jQuery/AJAX:
<!-- your animated loading image -->
<img src="http://i600.photobucket.com/albums/tt82/ugmhemhe/preloader.gif" id="loader" style="display: none;" />
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<!-- <script type="text/javascript" src="jquery.min.js"></script> -->
<script type="text/javascript">
$(document).ready(function(){
// before the request, show the GIF
$('#loader').show();
$.ajax({
url: document.URL, // JUST A SAMPLE (url_check_user_avail_status)
type: 'POST',
data: {request: true},
dataType: 'JSON',
// data: "value_email_mobile=" + value_email_mobile,
success: function(response) {
// After a succesful response, hide the GIF
$('#loader').fadeOut();
alert(response.message);
}
});
});
</script>
My assumption is, since this is just a simple email checking, this wont really take a chunk of time. The other way is to fake the loading process.
success: function(response) {
// After a succesful response, hide the GIF
// Fake the loading time, lets say 3 seconds
setInterval(function(){
$('#loader').fadeOut();
alert(response.message);
}, 3000);
}
Let us know what part of your code is not working?
1) Check if the request flow is hitting the function checkEmail? PHP has inbuilt JSON converting utility json_encode. You could start using that.
2) If you want to store this on the server for further use, you could think about usage like
a) Storing it in Database (If really needed based on your requirements. Note: This is always expensive)
b) Session - If you would want this info to be available for all the other users too.
c) Or keep it in the memory like any of the caching mechanisms like memcache etc
3) For displaying the busy display,
// Before the below ajax call, show the busy display
$.ajax({
});
// After the ajax call, hide the busy display.
You could do this using JavaScript / JQuery on your choice.
I remember using
JSON.parse(data)
to convert JSON ino a javascript object.
Jquery has its own JSON parser btw. Something like $.JSONParse(data)