I am trying to get some data, into a webpart in SiteA, from a document library in SiteB using an ajax call. When I added my code to a content editor it worked properly. However when added it to the webpart it didn't work. Here's my code :

function GetBalance(LoginName) {

var listName = "ListName";
var site = "SiteB";

var Local_Global_Balance;

var Ownurl = site + "_api/web/lists/getbyTitle('"+listName+"')/items?$select=VirtualBalance&$filter=EmployeeName eq '" + LoginName + "'";
    url: Ownurl,
    contentType: "application/json;odata=verbose",
    headers: {
        "accept": "application/json;odata=verbose",
        "X-RequestDigest": $("#__REQUESTDIGEST").val()
    async: false,
    success: function (data) {
        var items = data.d.results;
        if (items[0].VirtualBalance != "" ) {
            itemId = items[0].VirtualBalance;
            Local_Global_Balance = itemId;
        else {

    error: function (data) {
        console.log("An error occurred. Please try again.");


Any idea on how to solve this ?

  • 2
    What kind of webart are you trying to add it to? Also, did you include <script type="text/javascript> </script> tags around your code? – Kyle Rogers-Brodeur Feb 11 at 15:52
  • visual web part created in visual studio and deployed in the SiteA – Sam Feb 11 at 15:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.