Note that there are some explanatory texts on larger screens.

plurals
  1. POjQuery plugin with multiple functions
    primarykey
    data
    text
    <p>I currently have a web based application which strictly relies on a 3rd party soap server to supply the site with information. This application has little to no javascript, a few elements pulled from jQuery UI and a few jQuery things (more for simplicity than any other reason). </p> <p>This application is coming back around for feature enhancements and my thoughts are based on the soap server we rely on for data and each soap request requires a round trip we really want to reduce making multiple round trips on a single http request. Therefore, my thought was to make the application ajax based and only update content areas where the user wishes to see. </p> <p>So we have this server side library, php based, which uses soap to get information, generate HTML and send that data to the user. Now the fun begins, we want to take this server side code and make it modular and build a jQuery plugin to interact with server side. The part I am having trouble gathering is how to have multiple functions in a plugin (perhaps this is the wrong approach, please correct me) where I can call each one at will. </p> <p>The basic idea is the following: </p> <p>The soap server allows access to all of its underlying tables, each table has a specific WSDL and defines a set of functions available for each table. These functions are the same for all tables. </p> <p>We have for example: </p> <ul> <li>get</li> <li>getRecords</li> <li>insert</li> <li>update</li> <li><p>delete</p> <pre><code>(function( $ ){ var methods = { init: function( options){ //initialize the plugin return this.each(function(){ var $this = $(this), data = $this.data(); }); }, get : function(id){ var getQuery = 'sys_id='+id; $.ajax({ type: "POST", url: "get.php", data: getQuery, cache: false, success: function(result){ if(result.error){ //error notify user error occured... }else{ //success, update user ... } } }); return false; }, getRecords : function( ){ }, }; $.fn.myPlugin = function ( method ){ if( methods[ method ]){ return methods[ method ].apply(this, Array.prototype.slice.call( arguments, 1 )); }else if(typeof method === 'object' || !method){ return methods.init.apply(this, arguments); }else{ $.error('Method ' + method + 'does not exist on jQuery.ServiceNow'); } }; })( jQuery ); </code></pre></li> </ul> <p>So a get call to soap server would require a ID to identify which record in the table, a getRecords call accepts a query and returns multiple records, insert inserts a record, update updates a record etc. </p> <p>To perform a get call I wanted to do something such as:</p> <pre><code> $("#div").myPlugin.get(arguments); </code></pre> <p>The result would be that the div with id="div" would be updated with the return of whatever the get Function in the plugin myPlugin defined to do with that element. </p> <p>Is this the right approach, is there a better approach, am I all wet? This is my first jQuery plugin and I feel I am coming from the object oriented world where I am used to constructed things and then calling functions/methods of them and/or using fields. And maybe this is the problem that my mentality is off. </p> <p>Appreciate comments/feedback! </p> <p>My thoughts were to construct something similar in a jQuery plugin to be able to pass these calls to the server and the php on the server would determine the WSDL location based on what resource you want. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload