I have built my first client side web part as mentioned on this link https://docs.microsoft.com/en-us/sharepoint/dev/spfx/web-parts/get-started/build-a-hello-world-web-part. now the web part will show a simple hello word.
But i have the following JavaScript :-
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script><div id="123123">123</div><script type="text/javascript"> var idfromurl = window.location.href;// do extra steps to get the item id.... $(function () { var url = "/_api/web/lists/getbytitle('Dept')/items?$filter=ID eq idfromurl&$select=ID,Title,desc&$orderby= Title asc"; var html=""; $.ajax({ url: url, method: "GET", headers: { "Accept": "application/json; odata=verbose" }, success: function (data) { if(data.d.results.length>0){ var items=data.d.results; for(var i=0;i<items.length;i++){ html+= items[i].Title + "|"+ items[i].desc+"<br/>"; } $("#123123").after(html); } }, error: function (data) { } }); });</script>
which will get a parameter from a url, and send an api call to get an item description and item title, and should then render the result inside the web part.
but i am not sure where inside my web part project i can add this javascript code? should it be inside the.ts
file under thepublic render(): void
method?
second question:- now in my above JavaScript code, it will run under the login user permission. so if the login user can not access the List the user will not be able to see the item title & description inside the web part.. so my question is:- if i can run my above JavaScript code in elevated privilege ? so regardless of the of login user permission on the list, the user should be able to see the item title and description inside the SPFX ??
Thanks