1

I want to know how implement javascript method to create new item by using sitecore item web api.I am trying for below code my self.

But in the browser console show this error: XMLHttpRequest cannot load http://myproject/-/item/v1/sitecore/Content/Home?name=MyItem5&template=Sample/Sample%20Item&sc_database=master. Request header field X-Scitemwebapi-Password is not allowed by Access-Control-Allow-Headers.

Please can anyone help me!!!!!!!

function createItem(){
jQuery.ajax({
crossDomain: 'true',
type: 'POST',
url: 'http://myproject/-/item/v1/sitecore/Content/Home?name=MyItem5&template=Sample/Sample Item&sc_database=master',
dataType: 'JSON',
contentType: 'application/x-www-form-urlencoded',

     headers:{
     "X-Scitemwebapi-Username":"sitecore\\Admin",
     "X-Scitemwebapi-Password":"b",
    },


success: function(data) {

    alert(JSON.stringify(data));
},
error: function(res, error){
alert(JSON.stringify(res))
    alert(res+ ' something is wrong');
 }

}); }

Martin Davies
  • 4,436
  • 3
  • 19
  • 40
VIMUKTHI
  • 11
  • 2

1 Answers1

1

Make sure you have these settings in your Sitecore.ItemWebApi.config

itemwebapi.mode="StandardSecurity"
itemwebapi.allowanonymousaccess="false"/>
Ian Graham
  • 3,206
  • 1
  • 15
  • 23
  • Thanks golden grahams.I tried for your suggestion.But it is not like security configuration issue.seems like issue of cross domain or header request. – VIMUKTHI May 18 '15 at 09:02
  • Ok, was worth a shot. Another thing to try - Add the headers to the list of custom headers. Have a look at this http://stackoverflow.com/questions/12409600/error-request-header-field-content-type-is-not-allowed-by-access-control-allow – Ian Graham May 18 '15 at 13:05
  • golden grahams, Thanks for ur kindly reply.Still I am in trouble. – VIMUKTHI May 19 '15 at 05:47
  • request states 200.It means request successful but issue with authentication for sitecore. – VIMUKTHI May 19 '15 at 06:28