javascript - Is there a way to wrap this JS call neatly? -


let's have:

var details = {         method: 'post',         url: 'http://example.com/',         async: true,         params: {'param1': '1', 'param2': '2'},         headers: {'if-modified-since': 'sat, 1 jan 2000 00:00:00 gmt', 'cache-control': 'max-age=0'},         contenttype: 'text' };  kango.xhr.send(details, function(data) {         if (data.status == 200 && data.response != null) {                 var text = data.response;                 kango.console.log(text);         }         else { // went wrong                 kango.console.log('something went wrong');         } }); 

is there way wrap more neatly somehow - variables change / post, i'm thinking like:

call('post', function(data) {});

is possible?

i'm not familiar enough js.

just wrap logic in function this:

function getdata(method) { var details = {         method: method,         url: 'http://example.com/',         async: true,         params: {'param1': '1', 'param2': '2'},         headers: {'if-modified-since': 'sat, 1 jan 2000 00:00:00 gmt', 'cache-control': 'max-age=0'},         contenttype: 'text' };  kango.xhr.send(details, function(data) {         if (data.status == 200 && data.response != null) {                 var text = data.response;                 kango.console.log(text);         }         else { // went wrong                 kango.console.log('something went wrong');         } }); } 

and call getdata('post') or getdata('get').


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -