I'm using SPService in a list for take some information from an other list.
It works just sometimes... I need to refresh lot of time before it works ....
Here is my code :
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.12/jquery-ui.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/jquery.SPServices/0.7.1a/jquery.SPServices-0.7.1a.min.js"></script>
<script type="text/javascript">
_spBodyOnLoadFunctionNames.push("getToolInfo(807)");
function getToolInfo(lastID) {
var CamlQuery = "<Query><Where><Eq><FieldRef Name='ID'/><Value Type='Counter'>" + lastID + "</Value></Eq></Where></Query>";
var CamlViewFields = "<ViewFields><FieldRef Name='ID' /><FieldRef Name='Title' /></ViewFields>";
// this let me know that the function is getting called and passed the correct parameter value
alert('function called and passed last ID of : ' + lastID);
$().SPServices({
operation: "GetListItems",
async: true,
listName: "{D28F8F6B-9EFD-4FCA-9A2E-3A419EFCF637}",
CAMLViewFields: CamlViewFields,
CAMLQuery: CamlQuery,
completefunc: function (xData, Status) {
alert(xData.responseText);
console.log( xData.responseText );
$(xData.responseXML).SPFilterNode("z:row").each(function() {
//here is where we are reading the field values and putting them in JavaScript variables
//notice that when we read a field value there is an "ows_" in front of the internal field name.
//this is a SharePoint Web Service quirk that you need to keep in mind.
//so to read a field it is ALWAYS $(this).attr("ows_<internal field name>");
//get the title field (Speaker's Name)
var ID=($(this).attr("ows_ID"));
alert(ID);
//get the blog url, SharePoint stores a url in the form of <url><comma><description>
//We only want the <url>. To accomplish this we use the javascript "split" function
//which will turn <url><comma><description> into an array where the first element [0]
//is the url. Catch all that? if you didn't this is another reason you should be
//a developer if you are writing JavaScript and jQuery :)
});
}
});
}
The first alert : alert('function called and passed last ID of : ' + lastID); work all the time.
The second alert : alert(xData.responseText); work 1 in 5 time
And the last alert : alert(ID); work 1 in 8 time .....
And i really don't know why or how to fix it .... And it works only on IE and chrome not in firefox ...
Any idea ?