0

following is the code:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>

<div id="ResultDiv"></div>
<script language="javascript" type="text/javascript">  

function getListItem(url, listname, id, complete, failure) {
alert('hi');
    // Getting our list items
    $.ajax({
        url:'http://wzspf2:300/sites/Sample'/ + "/_api/web/lists/getbytitle('" + CompanyInfo + "')/items(" + id + ")",
        method: "GET",
        headers: { "Accept": "application/json; odata=verbose" },
        success: function (data) {
            // Returning the results
            complete(data);
        },
        error: function (data) {
            failure(data);
        }
        });
    }
} 
</script>

but i am getting failed to load error. Please give me solution asap. Can you explain how to retrieve lookup values in sharepoint list

0

Check your url. Seems like you have a backslash after .../Sample

In order to get Lookup values you have to use the expand and select operator.

Look here link

0

Change the url property to:

url: "http://wzspf2:300/sites/Sample" + "/_api/web/lists/getbytitle('" + CompanyInfo + "')/items(" + id + ")"

I also can give you the advice to use pnp js for REST calls. With pnp js it is much easier to work with.

If you want to receive LookUp Values you have to use expand and select operator as mentioned before. So for example if List "CompanyInfo" has a column called myLookUp which is a LookUp to another List you can use something like:

url: "http://wzspf2:300/sites/Sample" + "/_api/web/lists/getbytitle('" + CompanyInfo + "')/items(" + id + ")" + "?$expand=myLookUp&$select=myLookUp/Id"

Please let us know if you got it to work.

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.