首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > Ajax >

js带参数的回调函数

2012-03-14 
js带参数的回调函数 - Web 开发 / Ajaxjuqery里边,ajax是这么写的JScript codefunction getData(fun){$.aj

js带参数的回调函数 - Web 开发 / Ajax
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是我传递进来的回调函数,怎么实现
}

????不理解
[解决办法]
糊涂,看不懂,没表达清楚

[解决办法]
探讨
我现在怎么实现
getData(function(response){//这个地方怎么能获取到值});
success: function (response) {
fun(response) //fun是我传递进来的回调函数,怎么实现
}

????不理解

热点排行