Quantcast
Channel: MSDN Blogs
Viewing all articles
Browse latest Browse all 29128

Accessing Resx file in javascript

$
0
0

Here is the way to read Resource.resx files in javascript functions

<script type ="text/javascript">
         var currentUICluture = null;

         $(document).ready(function () {
             SP.SOD.executeOrDelayUntilScriptLoaded(LoadResourceJS, 'core.js');
         }); //end of document.ready 

SharePoint gives us the ScriptResx.ashx handler which loads the resource file in the js format on the Page.It provides the Res variable which contains all the resources keys in hashTable format.

         function LoadResourceJS() {
             currentUICluture = STSHtmlEncode(Strings.STS.L_CurrentUICulture_Name);
             SP.SOD.executeFunc('sp.js', 'SP.ClientContext', getResourceVal);
         }// end of ResourceJS

         function getResourceVal() {
             var url = '/_layouts/15/ScriptResx.ashx?culture=' + currentUICluture + '&name=resourceFileName';
             $.getScript(url, function () {
                 alert(Res[key]); //for specific key

              alert(Res.Key);

             });
         }//end of getResourceVal
   
   </script

 

 

NOTE: key the first alphabet of the key should be in lowercase.


Viewing all articles
Browse latest Browse all 29128

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>