I want to move “data” variable to out of success function for other operation.
$("a[class=note]").click(function( evt ){
var note = $(this).attr("value");
var preid = $(this).attr("id");
$.ajax({
type: 'GET',
url: 'style/ajax.php',
data: 'do=note&value=' + note + '&preid=' + preid,
success: function(data)
{
alert(data);
}
});
});
For example php have Global pharase..
global var(which is the worse solution, but this is what you asked for):
global variable are dangerous, Maybe variable outside the success scope is enough?
Var outside the
successcallback:Last option is to have a hidden input that will store the data;
Things to notice:
a[class=note]toa.notewhich is better.successis a callback which means it will not be fired until the response reach the client, until then your global\outside var\hidden input value will be null. if you don’t want theajaxto beasynchronousyou can define it in the options like this: