/ Published in: jQuery
Just syntax examples here. First block reads, second writes. Top function just a debugging helper.
Using jquery 1.5, $(xData.responseXML).find("nodeName=z:row]").each(function(i)... may need to be written as
$(xData.responseXML).find("nodeName='z:row']").each(function(i)... with single quotes around 'z:row'.
Using jquery 1.5, $(xData.responseXML).find("nodeName=z:row]").each(function(i)... may need to be written as
$(xData.responseXML).find("nodeName='z:row']").each(function(i)... with single quotes around 'z:row'.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
function printObject(o){ var output = ''; for (property in o) { output += property + ': ' + o[property]+'; '; } alert(output); } function readThenWrite(){ $().SPServices({ operation: "GetListItems", webURL: "/sitepath", /*optional parameter used if list lives in parent site */ async: false, listName: "Badge Achievements", /*name of the list */ viewName: '{D6ED584C-4673-4B89-B539-FF43D936ABC9}',/*optional to specify view */ CAMLRowLimit: 4, /*optional to limit results */ CAMLQuery: '<Query><Where><Eq><FieldRef Name="Author" /><Value Type="User">' + userName + '</Value></Eq></Where></Query>', completefunc: function (xData, Status) { //printObject(xData); $(xData.responseXML).find("[nodeName=z:row]").each(function(i) { arrBadgesAchvd[i] = $(this).attr('ows_Badge').split("#")[1]; }); } });/*-End SpServices*/ $().SPServices({ operation: "UpdateListItems", async: false, listName: "Learning Path Completion", updates: "<Batch OnError='Continue'>" + "<Method ID='1' Cmd='Update'>" + "<Field Name='Title'>percDone</Field>" + "<Field Name='User'>" + userID + "</Field>" + "<Field Name='Completed'>" + lpdone + "</Field>" + "<Field Name='Total'>" + lptotal + "</Field>" + "<Field Name='ID'>" + docid + "</Field>" + "</Method>" + "</Batch><Where></Where>", completefunc: function(xData, Status) {} });//End SPSErvices }/*End readThenWrite*/