1

First time playing in this environment: Sharepoint 2010. I have access to very limited tools: browser, notepad and the Internets. Feeling a bit rusty, haven't programmed in a while and I'm having a case of feeling lost right now.

Trying to read a SP list using AJAX. I have reached this 400 Bad Request Error as per the title. Here is the error I am receiving in the console:

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<error xmlns="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
  <code></code>
  <message xml:lang="en-CA">Error reading syndication item: 'Data at the root level is invalid. Line 1, position 1.'.</message>
</error>

Below is my request, and the source code of the list I am trying to read.

I am trying to read the list into a javascript var, but if I am not able to get past the 400 error I am stuck. Thank you for anyone that can correct me.

Here is my request:

function getRFCList(){
  var data = "_vti_bin/listdata.svc/RFCExtract";
  var url = BASE_URL + data;
  var thing = {};
    thing.title = "LinkTitle";
    var body = Sys.Serialization.JavaScriptSerializer.serialize(thing);

  console.log(url); //checked url it loads the list correctly

  $.ajax({
        type: "POST",
        url: url,
        processData: false,
        contentType: "application/atom+xml",
        data: body,
        error: function(ts) {    
                    console.log(ts.responseText); 
                    console.log(ts);
               },
        success: function (data) {
                alert(data);
               }
        });
  };

Here is the source code for the url that loads the list.

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<feed xml:base="<**BASE_URL**>/_vti_bin/listdata.svc/" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns="http://www.w3.org/2005/Atom">
  <title type="text">RFCExtract</title>
  <id><**BASE_URL**>/_vti_bin/listdata.svc/RFCExtract</id>
  <updated>2018-11-29T12:43:44Z</updated>
  <link rel="self" title="RFCExtract" href="RFCExtract" />
  <entry m:etag="W/&quot;1&quot;">
    <id><**BASE_URL**>/_vti_bin/listdata.svc/RFCExtract(1)</id>
    <title type="text">Test</title>
    <updated>2018-11-28T15:07:57-05:00</updated>
    <author>
      <name />
    </author>
    <link rel="edit" title="RFCExtractItem" href="RFCExtract(1)" />
    <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/CreatedBy" type="application/atom+xml;type=entry" title="CreatedBy" href="RFCExtract(1)/CreatedBy" />
    <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/ModifiedBy" type="application/atom+xml;type=entry" title="ModifiedBy" href="RFCExtract(1)/ModifiedBy" />
    <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Attachments" type="application/atom+xml;type=feed" title="Attachments" href="RFCExtract(1)/Attachments" />
    <category term="Microsoft.SharePoint.DataService.RFCExtractItem" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" />
    <content type="application/xml">
      <m:properties>
        <d:ContentTypeID>0x010018E49BFAAA76C74C8D9E319D13220A60</d:ContentTypeID>
        <d:Title>Test</d:Title>
        <d:Class m:type="Edm.Double">1</d:Class>
        <d:Status>Closed</d:Status>
        <d:Date m:type="Edm.DateTime">2010-11-01T00:00:00</d:Date>
        <d:RFCNumber m:type="Edm.Double">1</d:RFCNumber>
        <d:Id m:type="Edm.Int32">1</d:Id>
        <d:ContentType>Item</d:ContentType>
        <d:Modified m:type="Edm.DateTime">2018-11-28T15:07:57</d:Modified>
        <d:Created m:type="Edm.DateTime">2018-11-28T15:07:57</d:Created>
        <d:CreatedById m:type="Edm.Int32">9929</d:CreatedById>
        <d:ModifiedById m:type="Edm.Int32">9929</d:ModifiedById>
        <d:Owshiddenversion m:type="Edm.Int32">1</d:Owshiddenversion>
        <d:Version>1.0</d:Version>
        <d:Path>/sp/CCSB/Lists/RFC Extract</d:Path>
      </m:properties>
    </content>
  </entry>
  <entry m:etag="W/&quot;1&quot;">
    <id><**BASE_URL**>/_vti_bin/listdata.svc/RFCExtract(2)</id>
    <title type="text">Test Record 2</title>
    <updated>2018-11-29T07:42:19-05:00</updated>
    <author>
      <name />
    </author>
    <link rel="edit" title="RFCExtractItem" href="RFCExtract(2)" />
    <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/CreatedBy" type="application/atom+xml;type=entry" title="CreatedBy" href="RFCExtract(2)/CreatedBy" />
    <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/ModifiedBy" type="application/atom+xml;type=entry" title="ModifiedBy" href="RFCExtract(2)/ModifiedBy" />
    <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Attachments" type="application/atom+xml;type=feed" title="Attachments" href="RFCExtract(2)/Attachments" />
    <category term="Microsoft.SharePoint.DataService.RFCExtractItem" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" />
    <content type="application/xml">
      <m:properties>
        <d:ContentTypeID>0x010018E49BFAAA76C74C8D9E319D13220A60</d:ContentTypeID>
        <d:Title>Test Record 2</d:Title>
        <d:Class m:type="Edm.Double">2</d:Class>
        <d:Status>Pending</d:Status>
        <d:Date m:type="Edm.DateTime">2018-11-02T00:00:00</d:Date>
        <d:RFCNumber m:type="Edm.Double">2</d:RFCNumber>
        <d:Id m:type="Edm.Int32">2</d:Id>
        <d:ContentType>Item</d:ContentType>
        <d:Modified m:type="Edm.DateTime">2018-11-29T07:42:19</d:Modified>
        <d:Created m:type="Edm.DateTime">2018-11-29T07:42:19</d:Created>
        <d:CreatedById m:type="Edm.Int32">9929</d:CreatedById>
        <d:ModifiedById m:type="Edm.Int32">9929</d:ModifiedById>
        <d:Owshiddenversion m:type="Edm.Int32">1</d:Owshiddenversion>
        <d:Version>1.0</d:Version>
        <d:Path>/sp/CCSB/Lists/RFC Extract</d:Path>
      </m:properties>
    </content>
  </entry>
</feed>
0

Until User LZ-MSFT posts his solution here, I will reference it so others can view the correct method to read data.

Please refer to the solution provided by LZ-MSFT in the post of How to Read SP list into javascript - SPServices.SPGetListItemsJson returns key value pairs which do not belong to dataset. His solution uses REST API with jQuery Ajax.

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.