admin管理员组文章数量:1334887
I'm trying to get the success data from a jquery Ajax call so I can use it elsewhere but for some reason its only accessible within the actual success call, so immeditaly below works but the other doesnt'.. any advice is appreciated
success: function(data) {
alert (data)
}
this doesn't work when I try to pass "data" onto another function
$.ajax({
type: 'POST',
url: 'http://localhost/site1/utilities/ajax_ponent_call_handler',
data: {
ponent_function: ponent_function,
param_array: param_array
},
dataType: "json",
success: function(data) {
receiver (data)
}
});
}
my ajax success is calling this:
function receiver (data) {
ajax_return = data
alert (ajax_return)
}
I'm trying to get the success data from a jquery Ajax call so I can use it elsewhere but for some reason its only accessible within the actual success call, so immeditaly below works but the other doesnt'.. any advice is appreciated
success: function(data) {
alert (data)
}
this doesn't work when I try to pass "data" onto another function
$.ajax({
type: 'POST',
url: 'http://localhost/site1/utilities/ajax_ponent_call_handler',
data: {
ponent_function: ponent_function,
param_array: param_array
},
dataType: "json",
success: function(data) {
receiver (data)
}
});
}
my ajax success is calling this:
function receiver (data) {
ajax_return = data
alert (ajax_return)
}
Share
Improve this question
edited Aug 11, 2010 at 16:56
bakkal
55.5k12 gold badges136 silver badges113 bronze badges
asked Aug 11, 2010 at 16:55
RickRick
17k35 gold badges113 silver badges163 bronze badges
3
- does your receiver function get called? Have you checked in firebug? Also, are you doing this inbetween script tags or in a plugin/object? – hvgotcodes Commented Aug 11, 2010 at 17:02
-
Your code should work. Are you sure
receiver()
is in the proper scope? For example, if the$.ajax()
call is outside$(document).ready(function() {...})
, but thereceiver()
is inside, thenreceiver()
will not be visible from where you're calling it. – user113716 Commented Aug 11, 2010 at 17:03 - the issue was the var name "data", it was calling the function but not passing the data variable – Rick Commented Aug 11, 2010 at 17:09
2 Answers
Reset to default 3Don't use data
as a variable name. jQuery objects have an object called data
already which holds arbitrary data. If you call your variable dat
, you should get better results.
See http://api.jquery./jQuery.data/
A shorter implementation could be to just say success: receiver
with no parameters, and write your receiver signature as
function receiver(data, textStatus, XMLHttpRequest) {
/* ... */
}
Then data is passed by the jQuery callback.
Have you tried:
$.ajax({
type: 'POST',
url: 'http://localhost/site1/utilities/ajax_ponent_call_handler',
data: {
ponent_function: ponent_function,
param_array: param_array
},
dataType: 'json',
success: receiver
});
Or simply use another variable name other than data
as it is already used.
本文标签: JavaScriptJQuerypassing success data from AJAX to another functionStack Overflow
版权声明:本文标题:javascript - jQuery, passing success data from AJAX to another function? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742371161a2462266.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论