Sharepoint - How to get SPFieldChoice values using rest api SharePoint 2013?

I have solved my problem following way

 $.ajax({
        url: "host url"+"_api/web/lists/GetByTitle('List Name')/fields?$filter=EntityPropertyName eq 'Choice Field Name'",
        type: "GET",
        headers: {
            "accept": "application/json;odata=verbose",
        },
        success: function (data) {
            console.log(data.d.results[0].Choices.results);
        },
        error: function (error) {
            alert(JSON.stringify(error));
        }

    });

Below is the code for retrieving choices of choice field

function getFieldChoices(fieldName, listName) {
var dfd = $.Deferred();
hostweburl = decodeURIComponent(getQueryStringParameter('SPHostUrl'));
appweburl = decodeURIComponent(getQueryStringParameter('SPAppWebUrl'));

var urlTemplate = appweburl + "/_api/SP.AppContextSite(@target)/web/lists/getbytitle('#mylist')/fields?@target='" + hostweburl + "'&$select=Choices&$filter=Title eq  '#myfield'";
var url = urlTemplate.replace("#mylist", listName).replace("#myfield", fieldName);

$.ajax({
    headers: { "Accept": "application/json;odata=verbose" },
    contentType: 'application/json',
    url: url,
    success: function (data) {
        var result = data.d.results[0].Choices.results;
        var i = result.length;
        dfd.resolve(result);
    },
    error: function (err) {
        dfd.reject(err);
    }
});
return dfd;

}

Source http://sharepointfieldnotes.blogspot.in/2013/10/sharepoint-2013-rest-code-tips.html

Hope it helps.

Tags:

Rest