windows auth AGS service to html table

283
0
08-13-2018 01:37 PM
AwesomeEvan
Occasional Contributor

I would like to create a simple html table from a windows auth secured arcgis service.

I tried implementing JSON (from Feature Layer Query) to html table however I cant figure out consuming a secured service.

- The ags service is public facing with windows authentication

- The html page I'm creating is behind our firewall, so I can embed credentials if necessary.

The problem I get with the code below is simply (401 unauthorized) on the rest service url... strangely if I open this url in a new tab it I get the json no problem. 

I was playing with various scenarios of a token embedded in the url parameters with no success...

Any help would be appreciated. I plan to use this functionality a lot...

Cheers.

----------------------------

<!DOCTYPE html>
<html>

<head>
 <title> Json to table using Ajax Jquery getJSON</title>
 <script src="https://code.jquery.com/jquery-latest.js"></script>
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
 <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />
 <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>

<body>
 <div class="container">
 <div class="table-responsive">
 <h1> Cem Records</h1>
 <br />
 <table class="table table-bordered table-striped" id="cem_table">
 <tr>
 <th>PlotID</th>
 <th>First Name</th>
 <th>Last Name</th>
 </tr>
 </table>
 </div>
 </div>

</body>

</html>
<script>
 $(document).ready(function() {
 $.getJSON(
 'https://**SERVERNAME**/arcgis/rest/services/Society/CemeteryEDIT/MapServer/0/query?where=1%3D1&outFields=*&token=7Z6eykyhOFplxb_vd9W2-fzTlFLaP0sWK68WvWe3dyLeVOQD3qPDHp5GNx43to_F&f=json',
 function(data) {
 var cem_data = '';
 console.info(data.features);
 $.each(data.features, function(key, value) {
 cem_data += '<tr>';
 cem_data += '<td>' + value.attributes.PLOTID + '</td>';
 cem_data += '<td>' + value.attributes.FIRST_NAME + '</td>';
 cem_data += '<td>' + value.attributes.LAST_NAME + '</td>';
 cem_data += '<tr>';
 });
 $('#cem_table').append(cem_data);
 });
 });
</script>
0 Kudos
0 Replies