Domanda

I don't know JavaScript but I need to use SPServices on my company intranet. I need to write the fieldNames into some divs on my page, how do I do this? Here's the SPServices script:

<script type="text/javascript">
$( document ).ready(function(){
var thisUsersValues = $().SPServices.SPGetCurrentUser({
fieldNames: ["FirstName", "LastName", "Picture", "JobTitle", "WorkPhone", "WebSite",],
debug: false
});
</sript>

Thanks!

È stato utile?

Soluzione 3

Maybe this could help you :

var $userDescription = "<div>"+ thisUsersValues.toString() +"</div>";
$("#yourDivID").append($userDescription);

Altri suggerimenti

var thisUsersValues = $().SPServices.SPGetCurrentUser({
    fieldNames: ["FirstName", "LastName"], 
    debug: false
});

var name = thisUsersValues.FirstName + " " + thisUsersValues.LastName;
alert('Your name: ' + name);

I tested this and this is the correct usage. Just use "." syntax, or you could use thisUserValues['FirstName']; and thisUserValues['LastName']; to retrieve the properties.

From there, the other answer posted by Cana was correct:

var userDescription = "<div>" + name + "</div>";
var obj = $("#someObjId").append(userDescription);

I know this is old (I'm new to the site) but here is another option based off your JavaScript using DOM. It pulls the currentuser into a variable and using a DOM inserts into a div. This also works with an input field. Notice the .src for the picture.

<script type="text/javascript" language="javascript">
$(document).ready(function() {
    var userdetails = $().SPServices.SPGetCurrentUser(
    {
        fieldNames: ["ID","EMail","UserName","FirstName","LastName","Picture","JobTitle","WorkPhone","Office"],
        debug:false
    });

    document.getElementById('NameExample').innerHTML = (userdetails.FirstName + " " + userdetails.LastName);
    document.getElementById('PhotoExample').src = (userdetails.Picture);
    document.getElementById('EmailExample').innerHTML = (userdetails.EMail);
    document.getElementById('TitleExample').innerHTML = (userdetails.JobTitle);
    document.getElementById('OfficePhoneExample').innerHTML = ("Office" + " " +   userdetails.WorkPhone);
    document.getElementById('nameInputField').value = (userdetails.FirstName + " " + userdetails.LastName);
    document.getElementById('emailInputField').value = (userdetails.EMail);
    document.getElementById('OfficePhoneField').value = (userdetails.WorkPhone);
    document.getElementById('titleInputField').value = (userdetails.JobTitle);
});
</script>

<div>
    <span id="OfficePhoneExample"></span></br>
    <span id="EmailExample"></span></br>
</div>
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top