Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeDevelopment and...Development and...Building ExtensionsBuilding ExtensionsModulesModulesBest way of using ServiceFramework.jsBest way of using ServiceFramework.js
Previous
 
Next
New Post
12/13/2015 8:45 PM
 

Since the ServiceFramework.js as it seems needs to be in a $(document).ready to work, is there a better way than the sample below to handle it? I'm not really a JavaScript/jQuery expert. What would be the best way to use it in an AngularJS application? 


<asp:Button ID="btnHelloWorld" runat="server" Text="Get Hello World" OnClientClick="getHelloWorld(); return false;" />

<script type="text/javascript">

 

    var getHelloWorld;

 

    $(document).ready(function() {

        var sf = $.ServicesFramework(<%= ModuleId%>);

        var exampleControllerPath = sf.getServiceRoot('DataExchange') + 'Example/';

   

        getHelloWorld = function () {

            try {

                $.ajax({

                    type: "GET",

                    contentType: "application/json;charset=utf-8",

                    url: exampleControllerPath + 'HelloWorld',

                    beforeSend: sf.setModuleHeaders,

                    data: [],

                    success: function(result) {

                        result);

                    },

                    error: function(xhr, status, error) {

                        xhr.responseText);

                    }

                });

            } catch (e) {

                //Shouldn't do this but it's just for testing

                e.stack);

            }

        };

    });

</script>

 
New Post
12/13/2015 8:50 PM
 
What about skipping out on the $(document).ready and use something like this instead, does that have any drawbacks compared to using the ServiceFramework.js?

function getHelloWorld (){
try {
$.ajax({
type: "GET",
contentType: "application/json;charset=utf-8",
url: exampleControllerPath + 'HelloWorld',
headers: {
'ModuleId': <%= ModuleId %>,
'TabId': <%= TabId %>,
'RequestVerificationToken': sf.getAntiForgeryValue()
},
data: [],
success: function(result) {
result);
},
error: function(xhr, status, error) {
xhr.responseText);
}
});
} catch (e) {
//Shouldn't do this but it's just for testing
e.stack);
}
};
 
New Post
12/13/2015 8:51 PM
 
(DNN really needs to do something about this double post problem that is going on with the forums right now)
 
New Post
12/18/2015 9:19 AM
 
Not that it seems like anyone else but me tries to use the Service Framework (based on the activity in this thread) but I'll add another question anyway. 

 

The Service Framework offers methods for getting current ModuleID, TabID so that we can use these in JavaScript code, but couldn't we just as well pass these values using cookies / URL parameters instead just like the UserID is passed around? If so, couldn't we access these values just as easily through that as via the Service Framework methods? 

 
New Post
12/18/2015 10:24 AM
 
The core platform already "renders" the ModuleId and TabId into the page output.  The platform uses the ClientAPI to save those values as a variable which can be read using dnn.getVar().  This is exactly how ClientServices gets those values.  The serviceframework needs to be initialized in the document ready event since the values are rendered in a hidden element at the bottom of the page.  If you try to access the variables before the page finishes rendering then the hidden element may not exist and you won't be able to retrieve the values.

Joe Brinkman
DNN Corp.
 
Previous
 
Next
HomeHomeDevelopment and...Development and...Building ExtensionsBuilding ExtensionsModulesModulesBest way of using ServiceFramework.jsBest way of using ServiceFramework.js


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.

Content Layout

Subscribe to DNN Digest

Subscribe to DNN Digest

DNN Digest is our monthly email newsletter. It highlights news and content from around the DNN ecosystem, such as new modules and themes, messages from leadership, blog posts and notable tweets. Keep your finger on the pulse of the ecosystem by subscribing.  


Copyright 2017 by DNN Corp Terms of Use Privacy
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out