//Prepare ‘Account’ object and call create function
function createAccount() {
var new_nit = new Object();
// Set text field
new_nit.Name = "Maddy";
createRecord(new_nit, "new_nitSet", createAccountCompleted, null);
}
// This callback method executes on succesful account creation
function createAccountCompleted(data, textStatus, XmlHttpRequest) {
var nit = data;
alert("Account created; Id: ");
}
// This function creates record by making OData call
function createRecord(entityObject, odataSetName, successCallback, errorCallback) {
//Parse the entity object into JSON
var jsonEntity = window.JSON.stringify(entityObject);
// Get Server URL
var serverUrl = Xrm.Page.context.getServerUrl();
//The OData end-point
var ODATA_ENDPOINT = "/XRMServices/2011/OrganizationData.svc";
//Asynchronous AJAX function to Create a CRM record using OData
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
datatype: "json",
url: serverUrl + ODATA_ENDPOINT + "/" + odataSetName,
data: jsonEntity,
beforeSend: function (XMLHttpRequest) {
//Specifying this header ensures that the results will be returned as JSON.
XMLHttpRequest.setRequestHeader("Accept", "application/json");
},
success: function (data, textStatus, XmlHttpRequest) {
if (successCallback) {
successCallback(data.d, textStatus, XmlHttpRequest);
}
},
error: function (XmlHttpRequest, textStatus, errorThrown) {
if (errorCallback)
errorCallback(XmlHttpRequest, textStatus, errorThrown);
else
alert("Error on the creation of record; Error – "+errorThrown);
}
});
}
I'm using above code to create a entity called nit
. I have json2 and jQuery js files in web resource. When i run this code on button click, i'm getting error as No Transport
. when i searched , i got to know that this error is because of cross site scripting. How to enable cross site scripting or how to get rid of this error.