0

I am new to SPServices and trying start with example GetListItems. Below is my code

$(document).ready(function() { 
    GetTasks();
});

function GetTasks()
{

    var method = "GetListItems";
    var list = "Tasks";
    var fieldsToRead ="<ViewFields><FieldRef Name='Title'/></ViewFields>";
    var query ="<Query><Where><Eq><FieldRef Name='ID'/><Value Type='Counter'>1</Value></Eq></Where></Query>";
            $().SPServices({
            operation: method,
            async: false,  
            listName: list,
            CAMLViewFields: fieldsToRead,

              completefunc: function (xData, Status) { 
                    debugger;
                    $(xData.responseXML).find("z\\:row").each(function() { 

                       alert("hello");
                        var name = ($(this).attr("ows_Title"));
                    });                
                }
    });
}

The debugger in the completefunc is hit but when I check the status of function(xData, status) the status returns "error".And after this alert("hello") does not hit.

What is that I am doing wrong in this ?

5
  • It is before that I am getting the status as error Mar 30, 2015 at 17:35
  • @Amal Yes it is. Mar 30, 2015 at 17:38
  • @AmalHashim No it just gives "error". Mar 30, 2015 at 17:42
  • Where is this code being executed from? A webpart?
    – Paul T.
    Mar 30, 2015 at 22:45
  • @PaulT. It is being executed from the site home page and the task list is present in it. Mar 31, 2015 at 17:33

1 Answer 1

0

Try this sample

$(document).ready(function() {
    $().SPServices({
        webUrl: "http://weburl/"
        operation: "GetListItems",
        async: false,
        listName: "Tasks",
        CAMLViewFields: "<ViewFields><FieldRef Name='Title' /></ViewFields>",
        completefunc: function (xData, Status) {
            $(xData.responseXML).SPFilterNode("z:row").each(function() {
                alert($(this).attr("ows_Title"));                   
            });
        }
    });
});

Change webUrl to the current web where Tasks list resides.

4
  • It did not work. From which version of IE does spservices support. Mine is IE 8 . Is this the problem. Mar 30, 2015 at 17:46
  • Fiddler event log says AutoProxyDetection failed Mar 30, 2015 at 18:03
  • Is your SharePoint site on premise, do you have any proxy settings in IE? Mar 30, 2015 at 18:05
  • It is on premise and there are no proxy settings in IE Mar 30, 2015 at 18:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.