juqery里边,ajax是这么写的
- JScript code
function getData(fun){ $.ajax( type: "get", datatype: "json", cache: false, url: encodeURI("/ashx/User/userajax.ashx?action=4&uid=" + obj + "&type=" + types), success: function (response) {} );
这里边的sucess是回调函数,response是回调函数的返回值
我现在怎么实现
getData(function(response){//这个地方怎么能获取到值});
success: function (response) {
fun(response) //fun是我传递进来的回调函数,怎么实现
}
------解决方案--------------------
response这个参数其实是从你的服务器端返回的数据,就看你服务器端返回的数据是什么格式的,如果是文本,你可以直接拿来使用,如果是JSON格式的字符串,你可以在客户端序列化一下。eval('('+response+')') 然后,通过这个eval操作返回的对象来调用你服务端返回的JSON对象的成员。
------解决方案--------------------
我没看懂楼主要在success里边干什么?说的我都晕了
- JScript code
success: function (response) { //你要在getData里传一个直接运行的匿名函数? getData(function(response){ } ); }
------解决方案--------------------
我现在怎么实现
getData(function(response){//这个地方怎么能获取到值});
success: function (response) {
fun(response) //fun是我传递进来的回调函数,怎么实现
}
????不理解
------解决方案--------------------
糊涂,看不懂,没表达清楚
------解决方案--------------------