Note that there are some explanatory texts on larger screens.

plurals
  1. POExplaining jQuery AJAX Success Method
    text
    copied!<p>Im trying to use this jQuery script and this is confusing me:</p> <pre><code>function CallService() { $.ajax({ type : varType, //GET or POST or PUT or DELETE verb url : varUrl, // Location of the service data : varData, //Data sent to server contentType : varContentType, // content type sent to server dataType : varDataType, //Expected data format from server processdata : varProcessData, //True or False success : function(msg) {//On Successfull service call ServiceSucceeded(msg); }, error: ServiceFailed// When Service call fails }); } </code></pre> <p>The bit im confused about is the sucess object. The jQuery documentation says:</p> <pre><code>success(data, textStatus, jqXHR)Function, Array A function to be called if the request succeeds. The function gets passed three arguments: The data returned from the server, formatted according to the dataType parameter; a string describing the status; and the jqXHR (in jQuery 1.4.x, XMLHttpRequest) object. As of jQuery 1.5, the success setting can accept an array of functions. Each function will be called in turn. This is an Ajax Event. </code></pre> <p>But this method signature looks nothing like the:</p> <pre><code>success : function(msg) {//On Successfull service call ServiceSucceeded(msg); } </code></pre> <p>Object that we seem to be passing in.</p> <p>Questions:</p> <p>1) What does <code>function(msg){ServiceSucceeded(msg)}</code> mean?</p> <p>2) What is 'msg' in this context?</p> <p>3) How on earth am I meant to know how to structure the method sugnature for sucess?</p>
 

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