假设我有:
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 { // something went wrong
kango.console.log('something went wrong');
}
});
有没有办法以某种方式更整齐地包装它 - 就像我真正改变的唯一变量是 GET / POST,所以我在想这样的事情:
call('POST', function(data) {});
这可能吗?
我对JS还不够熟悉。