扫码关注官方订阅号
封装了一个ajax方法,想把回调函数作为封装好的参数传入,现在的做法是
function aa(m){ m(); } function bb(){ alert(1); } aa(bb);
能运行,但总感觉不对,上网查了查,有这么做的,不过也有说是错的,所以来问问各位大神,小弟拜谢!
代码如下,是这种逻辑
fn
function ajax(args) { $.ajax({ type: args.type || 'post', url: args.url, data: args.data, async: args.async || true, dataType: args.datatype || 'json', success: function (m, status, xhr) { args.success(m); }, error: function(xhr, status, error) { console.log('xhr.status: ' + xhr.status + ' status: ' + status); } }); }
调用
ajax({ url: 'http://', data: {}, success: function(j) { console.log(j); //显示ajax返回的值 } });
微信扫码关注PHP中文网服务号
QQ扫码加入技术交流群
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
PHP学习
技术支持
返回顶部
代码如下,是这种逻辑
fn
调用