Hi Everyone,
Greetings for the day!!!
I need a help regarding fetching records to html using webapi
I have written java-script code and the code is successfully executing but when it comes to html including i'm getting error please help on this.. See the below code and suggest me further where i have struck regarding the output.
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<link rel="stylesheet" href="cdnjs.cloudflare.com/.../font-awesome.min.css">
<script src="ClientGlobalContext.js.aspx" type="text/javascript"></script>
<script language="javascript" type="text/javascript">
function searchbutton() {
debugger;
var req = new XMLHttpRequest();
req.open("GET", window.parent.Xrm.Page.context.getClientUrl() + "/api/data/v9.0/accounts?$select=name", false);-->query is not reading the req.open method
req.setRequestHeader("OData-MaxVersion", "4.0");
req.setRequestHeader("OData-Version", "4.0");
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req.setRequestHeader("Prefer", "odata.include-annotations=\"*\"");
req.onreadystatechange = function () {
if (this.readyState === 4) {
req.onreadystatechange = null;
if (this.status === 200) {
var results = JSON.parse(this.response);
for (var i = 0; i < results.value.length; i++) {
//var accountid = results.value[i]["accountid"];
var name = results.value[i]["name"];
// console.log(name);
$("#tb").append("<tr><td>" + name + "</td></tr>");
}
} else {
Xrm.Utility.alertDialog(this.statusText);
}
}
};
req.send();
}
</script>
<body bgcolor="blue" onload="searchbutton()" style="word-wrap:break-word" >
<center><h1>Email formate Design</h1></center><br />
From : <input type="text" name="fromaddress" value="" align="left"><br />
To :
<select style="color : #fff " align="left">
<table id="tb" style="width:100%;">
<tbody>
<tr>
<th style="text-align:left">Name</th>
</tr>
</tbody>
</table>
</select>
<button onclick="searchbutton()" type="submit"><i class="fa fa-search"></i></button>
</body>
</head>
</html>
Regards,
Narendra
*This post is locked for comments