是否可以将值传递给success
函数?
function updateData(data_type){
var current_url = "myUrl";
var opc = data_type;
var dataset = [];
$.ajax({
data : {'type': opc},
url : current_url,
type : 'get',
success: function(data){
update(data)
}
});
console.log("update: " + data_type);
}
在success
函数中,我想访问我通过参数传递的data_type
变量。
这可能吗?
答案 0 :(得分:1)
直接使用它,如下所示:
function updateData(data_type){
var current_url = "myUrl";
var opc = data_type;
var dataset = [];
$.ajax({
data : {'type': opc},
url : current_url,
type : 'get',
success: function(data){
update(data, data_type);
}
});
console.log("update: " + data_type);
}
答案 1 :(得分:1)
function updateData( data_type ) {
var current_url = "myUrl";
var opc = data_type;
var dataset = [];
$.ajax( {
data : {'type': opc},
url : current_url,
type : 'get',
success: function( data ){
// `data_type` is available here, use as needed.
// You can pass it to other functions inside this one as well,
// i.e. the function below could be `update( data, data_type );`.
update( data );
}
} );
console.log( "update: " + data_type );
}