0

Hi I'm new to using SharePoint and I'm trying to transfer over an Employee Directory Search app from a website to SharePoint Foundation 2013.

I'm not able to use the same code in my .JS file and am having trouble figuring out what is wrong with it in SharePoint. Can anyone help me out?

I was able to console.log the data from my JSON file by removing dataType: 'json'and changing the .json filename to .js ... but I can't push the data into my employees array.

On my current website, the Array.prototype.push.apply(employees, data) works...but on SharePoint I am getting this error:

Uncaught TypeError: CreateListFromArrayLike called on non-object

so I tried using emploees.push(...data) and I am getting this error:

Uncaught RangeError: Maximum call stack size exceeded

Here is the function I am having trouble with.

function getADInfo(){
$.ajax({
    url: "/CustomWebparts/DirectorySearch/roster.js",
    method: 'GET',
    // dataType: 'json',
    cache: false,
    success: function(data) {
        console.log('success from getADInfo');
        // console.log(data);
        employees.push(...data);
        // Array.prototype.push.apply(employees, data);

        console.log(employees);
    },
    error: function(err) {
        console.error(err);
    }
});

}

  • If the contents of roster.js is JSON, have you tried making it roster.txt and then on the receiving end var receivedJson = JSON.parse(data); ? – Dylan Cristy Jun 6 at 21:12
  • @DylanCristy Ahh I thought I tried that earlier....thanks! – staysee Jun 6 at 21:20
  • @DylanCristy I'm getting a different error now..would you know how to help? Uncaught TypeError: Cannot read property 'addEventListener' of null -- I'm trying to select an input field using document.querySelector('.search'); for the eventlistener but its not working on sharepoint – staysee Jun 6 at 21:30
  • @staysee you should raise this as another question and provide your existing code for your addEventListener call. – James Randal Jun 7 at 4:07
  • @staysee did my suggestion work to get you your JSON data successfully? Let me know, if so I will post it as an answer. – Dylan Cristy Jun 8 at 14:49
0

If the contents of roster.js is just JSON, you could try making it roster.txt and then on the receiving end:

var receivedJson = JSON.parse(data);

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.