0

I get a 400 bad request with this ajax call, i tryied the caml query with caml designer and it should work. What is the problem?

        var soapEnv = "<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'>";
            soapEnv += "    <soapenv:Body>";
            soapEnv += "        <GetListItems xmlns='http://schemas.microsoft.com/sharepoint/soap/'>";
            soapEnv += "      <listName>PollUserData</listName>";
            soapEnv += "      <query>";
            soapEnv += "        <Query>";
            soapEnv += "              <OrderBy Override='TRUE'>";
            soapEnv += "                  <FieldRef Name='Created' Ascending='FALSE' />";
            soapEnv += "              </OrderBy>";   
            soapEnv += "          <Where>";
            soapEnv += "            <And>";
            soapEnv += "               <Eq>";
            soapEnv += "                   <FieldRef Name='UserID' />"
            soapEnv += "                   <Value Type='Text'>" + userGuid + "</Value>";
            soapEnv += "              </Eq>";
            soapEnv += "               <Eq>";
            soapEnv += "                   <FieldRef Name='QuestionID' />"
            soapEnv += "                   <Value Type='Text'>" + allQuestionsArray[i].ID + "</Value>";
            soapEnv += "              </Eq>";
            soapEnv += "           </And>";*/
            soapEnv += "       </Where>";
            soapEnv += "     </Query>";
            soapEnv += "    </query>";
            soapEnv += "      </viewFields>";
            soapEnv += "       <ViewFields>";
            soapEnv += "         <FieldRef Name='UserID'/>";
            soapEnv += "         <FieldRef Name='QuestionID'/>";
            soapEnv += "         <FieldRef Name='Question'/>";
            soapEnv += "         <FieldRef Name='Answer'/>";
            soapEnv += "       </ViewFields>";
            soapEnv += "      </viewFields>";
            soapEnv += "    </GetListItems>";
            soapEnv += "  </soapenv:Body>";
            soapEnv += " </soapenv:Envelope>";

            var port = window.location.port;
            if (port.length <= 0)
                port = "";
            else
                port = ":" + port;
            var webservice = _spPageContextInfo.webAbsoluteUrl + "/_vti_bin/lists.asmx";

            $.ajax({
              url: webservice,
            type: "POST",
            dataType: "xml",
            data: soapEnv,
            async: false,
            contentType: "text/xml; charset=\"utf-8\"",
            complete: function (xData, status) {
                $(xData.responseXML).find("z\\:row, row").each(function () {
            })
            }, error: function(xhr){
            }
            });
1

You have a closing tag at the beginning of the viewFields Block :

        soapEnv += "      </viewFields>";
        soapEnv += "       <ViewFields>";
        soapEnv += "         <FieldRef Name='UserID'/>";
        soapEnv += "         <FieldRef Name='QuestionID'/>";
        soapEnv += "         <FieldRef Name='Question'/>";
        soapEnv += "         <FieldRef Name='Answer'/>";
        soapEnv += "       </ViewFields>";
        soapEnv += "      </viewFields>";

replace by

        soapEnv += "      <viewFields>";
        soapEnv += "       <ViewFields>";
        soapEnv += "         <FieldRef Name='UserID'/>";
        soapEnv += "         <FieldRef Name='QuestionID'/>";
        soapEnv += "         <FieldRef Name='Question'/>";
        soapEnv += "         <FieldRef Name='Answer'/>";
        soapEnv += "       </ViewFields>";
        soapEnv += "      </viewFields>";

Which version of SP are you using ? Why do you have mutiple enclosed tags?

  • 1
    Thank you, that did the work. I am using multiple enclosed tags becouse of soap. – Anders Dec 8 '14 at 10:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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