javascript - Wrapper for JQuery's ajax function. Callback fired, but no params -


I'm very new to JavaScript, so the question can be dummy. I receive a lot of posts and post requests in my code, so I decided to write the javascript function to call java's AJAX function

request url url * @ The ultimate success callback function is triggered when the request successfully triggers * @complete failed callback function triggered unsuccessful request * / function getRequest (url, success callback, failed callback) {$ .ajax ({url: url} , Timeout : 3000, Datatype: "JSN"). Success: functions (data, textstats, jxaxhr) {successful callback (data, textstats, jxxhr);}, error: unsuccessful callback (jqaxhar, textstatus, errorstroke)}); }

I call it like this:

  url = "/ api / info"; Success on the Festival (data, textstats, jqXHR) {$ ("# results") Html ("hostname is" + datahostname); } Function onfell (jqXHR, textstats, error thrown) {$ ("# results"). Html ("Shutdown"); } // fire request getRequest (url, onSuccess (), onFail ());  

The callback has been removed, but the data is undefined. In the end, I have decided to type the function again by writing:

 
function getRequest (url, success callback, failed callback) {$. Axx ({url: url, timeout: 3000), datatype: "Jason", success: function (data, textstats, jquxhr) {successful callback (data, textstatus, jxxhr);}, error: function (jkxhr, textstats, errorprobion) {Fail callback (jkxhr, textstatus, error trace);}}); }

and its use is:

  getRequest (url, onSuccess, onFail); As told by @ Fabricator  


Comments

Popular posts from this blog

java - org.apache.http.ProtocolException: Target host is not specified -

java - Gradle dependencies: compile project by relative path -

ruby on rails - Object doesn't support #inspect when used with .include -