0

How to call cross domain rest call using SharePoint rest API 2013

posting data in SharePoint list from https://qa.sp.scb.org/en/whoweare/diversity/Pages/Admin.aspx

To

http://qa.sp.scb.org/fr/whoweare/diversity/_api/web/lists/GetByTitle('CurrentTheme')/items(2)",

getting Error -Response to the preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://qa.sp.scb.org' is therefore not allowed access. The response had HTTP status code 401.

Code-

function AddListItemFrench() 

    $.ajax({
        url: "https://qa.sp.scb.org/fr/whoweare/diversity/_api/web/lists/GetByTitle('CurrentTheme')/items(2)",
        type: "POST",
        data: JSON.stringify({
            __metadata: {
                type: "SP.Data.Current_x0020_ThemeListItem"
            },

            Title: setTitle,
            ThemeTitle: ThemeHeading,
            Image: setImage,
            BgImage: setbgImage,
            Tag: hashtag,
            RightTheme: RightmenuHasTag,
            HashtagTitleFrench:Hashtagfrench,
            ThemeTitleFrench:Themetitlefrench
        }),
        headers: {
            "Accept": "application/json;odata=verbose",
            "Content-Type": "application/json;odata=verbose",
            "X-RequestDigest": $("#__REQUESTDIGEST").val(),
            "IF-MATCH": "*",
            "X-HTTP-Method": "MERGE"
        },
        success: function(data, status, xhr) {
            console.log(" Theme update in  French version");

            $("#slectedtheme").text(setTitle);

        },
        error: function(xhr, status, error) {
            console.log("AddListItem is not update");
        }
    });
}
1
  • Using sp.js (JSOM) issue has been resolved Code
    – prashant
    Commented Oct 9, 2018 at 11:41

1 Answer 1

0

Using sp.js (JSOM) issue has been resolved

Code-

var siteUrl ='https://mysp.org/fr/inclusion/';

function updateListItemFrench() {

var clientContext = new SP.ClientContext(siteUrl);
var oList = clientContext.get_web().get_lists().getByTitle('Current Theme');

this.oListItem = oList.getItemById(2);

oListItem.set_item('Title', setTitle);
oListItem.set_item('Image', setImage );
oListItem.set_item('BgImage', setbgImage );
oListItem.set_item('RightTheme',  RightmenuHasTag );
oListItem.set_item('HashtagTitleFrench',  Hashtagfrench );
oListItem.set_item('ThemeTitleFrench', ThemeTitleFrench);

oListItem.update();

clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));

}

function onQuerySucceeded() {

console.log("Theme has been updated on french")

}

function onQueryFailed(sender, args) {

alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
alert ("faild")

}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.