SPServices not loading,but alerts are showing

May 16, 2013 at 7:20 AM
Hello,
here comes my scripts reference in the master page
<asp:ScriptReference Path="../../SiteAssets/js/jquery-1.8.3.js"></asp:ScriptReference>
<asp:ScriptReference Path="../../SiteAssets/js/jquery.SPService 0.7.2.js"></asp:ScriptReference>

and code here


//alert("jQuery loaded? " + (jQuery == undefined ? "NO!!!" : "YES."));
//alert("SPServices loaded? " + (jQuery.SPServices == undefined ? "NO!!!" : "YES."));

$(document).ready(function()
{
$().SPServices({
  operation: "GetGroupCollectionFromUser",
  userLoginName: $().SPServices.SPGetCurrentUser(),
  async: false,
  completefunc: function(xData, Status) {
   if ($(xData.responseXML).find("Group[Name='Site Admin']").length == 1) {
    alert('Yes,Its Admin')
    }   
         }
});
});

I tried the above commented lines,my jquery is getting loaded ,but SPService is giving a no alert(not loading :( ) .. I tried an alert insdie SPService and i successfully got the alert,i dont understand wats the prob is !! >> pls help
Coordinator
May 16, 2013 at 11:14 AM
Ann_v:

If the alert "Yes,Its Admin" is firing, then SPServices is working. Is that what you mean by "I tried an alert insdie SPService and i successfully got the alert"?

M.
Coordinator
May 16, 2013 at 11:15 AM
You only need to post your question in one thread. I see all of the posts!

M.
May 16, 2013 at 12:10 PM
oops..sorry for posting the same question in 2 threads...Thanks for the reply..
Inside SPServices.js i pasted an alert,that is working .But when i try in my page "alert("SPServices loaded? " + (jQuery.SPServices == undefined ? "NO!!!" : "YES.")); " this alert its giving me "SPServices loaded? No!!!" and "$().SPServices.SPGetCurrentUser()" is also throwing a null value
Coordinator
May 16, 2013 at 12:23 PM
Well, your alert is always going to say "NO!!!" the way you have it. This works:
alert("SPServices loaded? " + ($().SPServices == undefined ? "NO!!!" : "YES."));
What version of SharePoint are you using and what type of page are you calling the code from?

Your code runs fine for me in a console.

M.
May 16, 2013 at 12:35 PM
Edited May 16, 2013 at 12:39 PM
Yes U r right ... I got the alert "SPServices loaded? YES." But not the second alert..
I am using sharepoint 2010,my code is in a js file and am calling it from a master page .Actually i want to check the logged user is in a particular group or not ..

and also tried
var userName = $().SPServices.SPGetCurrentUser({
    fieldName: "Title",
    debug: true
});   
but alert (userName) is null
Coordinator
May 16, 2013 at 12:38 PM
Well, check that the user is in fact in that group and that the group is in the returned results. Given that SPServices is loaded and working, it'll be some debugging on your side at this point.

M.
May 16, 2013 at 12:46 PM
the same code is working with some other subsites ,but only for one particular subsite its not working . And all the subsites are pointed to the same js files in the parent site. May be some other issue...Anyways thanx for the reply ..