SPGetCurrentUser and userdisp.aspx

Jun 2, 2014 at 6:10 PM
When ever I try to use SPGetCurrentUser, I do not get any results. I can see that there is some sort of error: GET = Failed to load resource.

So I tried pasting in the URL that fails, the userdisp.aspx page. When I do that, I am re-directed to the person.aspx page. Is that why I am getting the error?

Is there anyway around this? I need to be able to get some sort of unique identifier of the current user, be it, ID or email, etc.

Jun 2, 2014 at 6:11 PM
Here is the error info I get out of Chrome's console:

[Error] Failed to load resource: cancelled
send ([native code], line 0)
send (jquery-1.8.3.min.js, line 2)
ajax (jquery-1.8.3.min.js, line 2)
SPGetCurrentUser (jquery.SPServices-2013.01.min.js, line 21)
(anonymous function) (nameTest.html, line 24)
l (jquery-1.8.3.min.js, line 2)
fireWith (jquery-1.8.3.min.js, line 2)
ready (jquery-1.8.3.min.js, line 2)
A (jquery-1.8.3.min.js, line 2)
Jun 2, 2014 at 7:36 PM
It should work no matter how you are set up, but people do some odd things.

Note that the URL the function "scrapes" is "/_layouts/userdisp.aspx?force=true". The force=true tells SharePoint not to go to the My Site person.aspx page.

Does it work in IE?

Jun 2, 2014 at 8:14 PM
The same thing happens in IE8. The page still redirects to My Site person.aspx.

It could be a quirk in how our sharepoint is installed.

I saw in some other comments that the ID should be available regardless of getting to that page, could you elaborate on that?


Jun 2, 2014 at 9:01 PM

It depends what version of SharePoint you're running. There's JavaScript variable called _spPageContextInfo.userId that will give you the current user's ID in SharePoint 2010 and 2013.