0

I have this working properly on Office 365, but when I move it to our on-premise installation, I get an error.

enter image description here

here is the code I'm trying to execute

<script type="text/javascript" src="//code.jquery.com/jquery-1.11.1.min.js"></script> 

<script type="text/javascript" src="//cdn.datatables.net/1.10.3/js/jquery.dataTables.min.js"></script>
<link  type="text/css" rel="stylesheet"  href="//cdn.datatables.net/1.10.3/css/jquery.dataTables.min.css" /> 

<script type="text/javascript" src="../SiteAssets/jquery.dataTables.rowGrouping.js"></script>


Enter State Abbreviation: <input type=text id="stateID" onkeyup="GetZips();"  size=5 maxlength="2"> 


<!-- MAKE SURE THAT YOU SPECIFY THE NAMES OF THE COLUMNS TO DISPLAY IN THE  THEAD ROW -->
<h1 id='title'></h1>
<table cellpadding="0" cellspacing="0" border="0" class="display" id="ZipViewTable">
<thead><th>County</th><th>Zip Code</th><th>City</th><th>Timezone</th><th>Area Codes</th><th>Latitude</th><th>Longitude</th><th>Population</th></thead>

<style type="text/css">

#ZipViewTable
{display:none;}

.expanded-group{
            background: url("../SiteAssets/minus.jpg") no-repeat scroll left  center transparent;
            padding-left: 15px !important;
            font-weight:bold;padding:5px;margin:5px;
        }

        .collapsed-group{
            background: url("../SiteAssets/plus.jpg") no-repeat scroll left center transparent;
            padding-left: 15px !important;
            font-weight:bold;padding:5px;margin:5px;
        }


</style>

<script type="text/javascript">

function GetZips()
{
    var state = ($("#stateID").val());
    if (state.length ==2)
    {
    //
    // MODIFY THE REST QUERY TO RETRIEVE THE FIELDS YOU NEED FROM THE YOUR SPECIFIC LIST
    // YOU CAN TEST YOUR REST QUERY IN THE BROWSER URL TO KNOW THE CORRECT FIELD NAMES TO USE
    // AND TO MAKE SURE YOUR FILTERS WORK
    //
    var call = $.ajax({
        url: _spPageContextInfo.webAbsoluteUrl + "/_api/Web/Lists/GetByTitle('zip')/items?$select=Id,Title,zip,primary_city,state,county,area_codes,timezone,latitude,longitude&$filter=state eq '"+state.toUpperCase()+"'&$top=5000",
        type: "GET",
        beforeSend: function(){$("#overlay").show();},
        complete: function(){$("#overlay").hide();},
        dataType: "json",
        headers: {
            Accept: "application/json;odata=minimalmetadata"
        }

    });
    call.done(function (data,textStatus, jqXHR){
            $("#ZipViewTable").dataTable({ 
                        "bDestroy": true,
                        "bProcessing": true,
                        "aaData": data.value,
                        //MAKE SURE YOU SPECIFY THE FIELDS YOU WANT TO DISPLAY IN THE LIST VIEW
                        //THE VALUE OF EACH "mData" PROPERTY IS THE FIELD NAME AS IT IS RETURNED
                        //FROM THE REST QUERY.  
                        "aoColumns": [
                            { "mData": "county" },
                            { "mData": "zip" },                    
                            { "mData": "primary_city" },
                            { "mData": "timezone", "searchable": false },                    
                            { "mData": "area_codes" },                    
                            { "mData": "latitude" },                    
                            { "mData": "longitude" }
                        ],
                        "iDisplayLength": 100,
                        "dom": '<"top"iflp<"clear">>rt<"bottom"iflp<"clear">>',
                        "bLengthChange": false,
                        "bProcessing": true,}).rowGrouping({
                            fnGroupLabelFormat: function(label) { return "COUNTY: "+ label + ""; } ,
                            bExpandableGrouping: true});            

        $("#ZipViewTable").show();
        $("#title").html("ZIP CODE INFORMATION FOR " + state.toUpperCase());    

        });

    call.fail(function (jqXHR,textStatus,errorThrown){
        alert("Error retrieving Tasks: " + jqXHR.responseText);
    });

    }
}

  • What version of SP do you have on prem? If SP1 is not installed, then you need to change the accept header to application/json;odata=verbose. <SP1 does not support JSON Light. – wjervis Mar 27 '15 at 19:55
1

Probably your version is SharePoint 2013 but without SP1 installed. If so, JSON Light is not supported.

If so, you could change metadata format from:

application/json;odata=minimalmetadata

to:

application/json;odata=verbose

If your version is SharePoint 2013 SP1, then make sure multiple metadata formats for JSON is turned on.

  • changing the metadata format to verbose solved the issue – Jason Mar 27 '15 at 22:41

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.