I solved it. This can be achieved in 2 ways:
$(document).ready(function() {
var soapEnv =
"<?xml version='1.0' encoding='utf-8'?> \
<soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'> \
<soap:Body> \
<GetUserProfileByName xmlns='http://microsoft.com/webservices/SharePointPortalServer/UserProfileService'> \
<AccountName>"+"DOMAIN\\UserID"+"</AccountName> \
</GetUserProfileByName> \
</soap:Body> \
</soap:Envelope>";
$.ajax({
url: "http://devsp10:2000/_vti_bin/userprofileservice.asmx",
type: "POST",
dataType: "xml",
data: soapEnv,
complete: processResult,
contentType: "text/xml; charset=\"utf-8\""
});
});
function processResult(xData, status) {
var cCode ;
$(xData.responseXML).find("PropertyData > Name:contains('CompanyCode')").each(function() {
cCode = $(this).parent().find("Values").text();
alert("cCode : "+ cCode);
});
}
OR Can be achieved by adding reference to SPServices from codeplex.
ExecuteOrDelayUntilScriptLoaded(init,'sp.js');
function init(){
var cCode;
$().SPServices({
operation: "GetUserProfileByName",
async: false,
AccountName: $().SPServices.SPGetCurrentUser(),
completefunc: function (xData, Status) {
$(xData.responseXML).find("PropertyData > Name:contains('CompanyCode')").each(function() {
cCode = $(this).parent().find("Values").text();
alert("Company Code : "+cCode);
});
}
});
}