0

I used that Ajax branding technique to load list items or any document library item into my design in Sharepoint 2010 now im working on 2013 and with the same technique i got failure

$.ajax({
url: '~/Lists/listname/AllItems.aspx',
data:{id:"#divId"},
dataType: "html"
success: function(data){
console.log($(data).find('table[summary="Awr Latest"]'));
}

});

in 2010 i got response with the table of content that i need now im getting a response with the masterpage and the content div but no table in it

any ideas ?

2

SharePoint 2013 uses a lot of client side rendering. This means while you load the content of your AllItems.aspx page, the list rows aren't contained in the html response. They would rendered dynamic via JavaScript.

But anyway, your ajax techique is very bad to get list items. ;)

Use something like this (it's called Java Script Object Model / JSOM):

function getListItems(onSuccess) {
    var clientContext = SP.ClientContext.get_current();
    var oList = clientContext.get_web().get_lists().getByTitle('Listname');
    var collListItem;

    var camlQuery = new SP.CamlQuery();
    var viewXML = '<View><Query><OrderBy></OrderBy><Where></Where></Query><RowLimit>5000</RowLimit></View>';
    camlQuery.set_viewXml(viewXML);
    
    collListItem = oList.getItems(camlQuery);
    clientContext.load(oList);
    clientContext.load(collListItem);

    clientContext.executeQueryAsync(
        function () {
            // We have the elements
            var listItemEnumerator = collListItem.getEnumerator();

            // It's easy to iterate and get the column values of an item
            while (listItemEnumerator.moveNext()) {
                var cItem = listItemEnumerator.get_current();
                console.log('Id: ' + cItem.get_id() + ', Title: ' + cItem.get_item('Title'));                           
            }

            // Run callback function if needed
            if (onSuccess) onSuccess(collListItem);
        },
        function (sender, args) {
            console.log('Error getting list items: ' + args.get_message());
        }
    );
 }

 // Run the function if SharePoint DOM and Object Model is ready
 _spBodyOnLoadFunctionNames.push('getListItems');   
12
  • Thank you im Learning from you i'll try your code now :) – Ahmed Aborady Jan 29 '15 at 10:34
  • now i got error SP.ClientContext.get_current() undifined ! – Ahmed Aborady Jan 29 '15 at 10:42
  • i replaced get_current() with site url the same error – Ahmed Aborady Jan 29 '15 at 10:42
  • Did you take this function and included the line with _spBodyOnLoadFunctionNames.push on your page? I think you are trying to call SP.ClientContext before SharePoint Object Model is ready. See sharepoint.stackexchange.com/questions/105667/… – Fensterbank Jan 29 '15 at 10:50
  • 1
    You need to include SP.JS file as well in the master page<SharePoint:ScriptLink language="javascript" name="SP.js" /> – Nadeem Yousuf-AIS Jan 29 '15 at 11:11
0

Now it Works after i added

<SharePoint:ScriptLink Name="MicrosoftAjax.js" runat="server" Defer="False" Localizable="false"/>
<SharePoint:ScriptLink Name="SP.core.js" runat="server" Defer="False" Localizable="false"/>
<SharePoint:ScriptLink Name="SP.js" runat="server" Defer="True" Localizable="false"/>

before any Scripts

3
  • Seeing the help provide by Fensterbank, I would have expected that you marked his response as answer instead of adding yours. – Nadeem Yousuf-AIS Jan 29 '15 at 11:43
  • aHA YES REALLY IM KINDA NEW USER HERE STILL UNDERSTANDING THERES NO WAY TO DO IT NOW ? – Ahmed Aborady Jan 29 '15 at 12:05
  • 1
    thank u also u are noticed the sp.js that was the problem really thanks Nadeem – Ahmed Aborady Jan 29 '15 at 12:07

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.