Hi,
I am new to REST callings.
Can you tell me what is difference between below type of calling REST services.
Below are two ways to create account record using REST, but what is the diference?
Is one is Ajax and Other is pure Javascript calling? or One is synchronous and other is Async?.
Please explain why two ways of calling to create a record?
======code====================
function createAccountRecord(Name){
var Name="Test account from rest";
alert("createAccountRecord function START");
var account = new Object();
account.Name = Name;
var jsonAccount = window.JSON.stringify(account);
var ODataPath="******XRMServices/2011/OrganizationData.svc";
var createAccountReq = new XMLHttpRequest();
createAccountReq.open("POST", ODataPath + "/AccountSet", true);
createAccountReq.setRequestHeader("Accept", "application/json");
createAccountReq.setRequestHeader("Content-Type", "application/json; charset=utf-8");
createAccountReq.onreadystatechange = function () {
createAccountReqCallBack(this);
};
createAccountReq.send(jsonAccount);
alert("createAccountRecord function END");
}
function createAccountRecord1(Name)
{
var account = new Object(); //=> ACCOUNT
account.Name= "Test rest";
var jsonEntity = JSON.stringify(account);
var serverUrl = Xrm.Page.context.getServerUrl();
var ODATA_ENDPOINT = "/XRMServices/2011/OrganizationData.svc";
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
datatype: "json",
url: "******"+ ODATA_ENDPOINT + "/" + 'AccountSet',
data: jsonEntity,
beforeSend: function (XMLHttpRequest) {
XMLHttpRequest.setRequestHeader("Accept", "application/json");
},
success: function (data, textStatus, XmlHttpRequest) {
alert("ok");
},
error: function (XmlHttpRequest, textStatus, errorThrown) {
alert("ajax call failed" + XmlHttpRequest.toString() + errorThrown.toString() + textStatus.toString());
}
});
}
Thanks in Advance
Krishna