I am making a jquery post request to obtain a part of the html code from server. There is a file on server get_info.php which prints html code for different requirements. I am using following code to do this :
function check(inf_type) {
$.ajax({
type: 'POST',
url: "get_info.php",
data: { "sequence_no" : 1 },
success: function(data) {
// how can i use value of variable "inf_type" here.
// here, the variable "data" contains HTML code.
},
dataType: 'text'
});
}
the function check() accepts a parameter inf_type which contains random strings according to which, server recognize the html code to print. Now, i want handle the POST response according to this inf_type.
How can i access the value of inf_type variable in POST response function? The function check() is called more often, thats why i can not put the inf_type variable value in any global variable.
What can i do to achieve that?
Please guide me. thanks in advance.
You can access it via
inf_typeparameter of thecheck()function:}
The reason why this works is because the inner function (success callback) has access to variables in the outer function (check). See this answer for more details: https://stackoverflow.com/a/111200/69868
Edit
This assumes that inf_type is a either a number or a new (different) instance of object in each call of
check(). Details are explained in the link mentioned above.