Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

142
Vistas
Getting [object Object] error in Javascript and can't identify the problem

I have a function below that when used on a webpage is causing the [object Object] error to occur and I was hoping someone could identify the issue for me. I am using this code to get the count of a items in particular SharePoint views so that I can display them in a dashboard for the users. Any suggestions appreciated.

function countViewItems(listTitle, viewName, elementClass) {
// Counts the number of items of in the view 'viewName' of the list 'listTitle'.

//get view query of the list view
$.ajax({
    url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('"+listTitle+"')/views/getbytitle('"+viewName+"')/ViewQuery",
    type: "GET",
    headers: { 
        "ACCEPT": "application/json;odata=verbose",
    },
    success: function (data) {
        var  viewQuery=data.d.ViewQuery;
        //get item count of view
        var viewXml = '<View><Query>' + viewQuery + '</Query></View>';
        var queryPayload = {  
            'query' : {
                '__metadata': { 'type': 'SP.CamlQuery' }, 
                'ViewXml' : viewXml  
            }
        };
        $.ajax({
            url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('" + listTitle + "')/getitems",
            type: "POST",
            data: JSON.stringify(queryPayload),
            headers: {
                "Accept": "application/json;odata=verbose",
                "X-RequestDigest": $("#__REQUESTDIGEST").val(),
                "Content-Type": "application/json; odata=verbose"
            },
            success: function (data) {
                var itemCount=data.d.results.length;
                $(elementClass).html(itemCount);
            },
            error: function (data) {                     
                alert(JSON.stringify(data));
            }
        });
    },
    error: function (err) {
        alert(err);
    }
});

}

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda