我有一个函数,它包含2$.ajax函数,这些函数具有不同的操作,但使用相同的数据我把这些数据放在一个对象中,如何为每个$.ajax函数添加不同的操作
在对象中必须使用相同的数据
var request_data = {
nonce: ajax_object.nonce,
category_id: cat_ids,
brand_name: brand_name_value,
orderby_meta_key: orderby_meta_key,
orderby: orderby,
order_type: order_type,
shop_view: shop_view
}
function ajax_filter(){
// firest ajax function
$.ajax( {
url: ajax_object.ajax_url,
type: 'post',
action:'shop_filter', ------> //not working like this
data: request_data,
success: function(feedback) {
}
})
// second ajax function
$.ajax( {
url: ajax_object.ajax_url,
type: 'post',
action: 'update_another_function', ----> //not working like this
cache: true,
data: request_data,
success: function(feedback) {
},
})
}
jQuery.ajax中没有操作参数,您的操作应该在请求数据中吗?
function ajax_filter(){
request_data.action = 'shop_filter';
// firest ajax function
$.ajax( {
url: ajax_object.ajax_url,
type: 'post',
data: request_data,
success: function(feedback) {
}
})
request_data.action = 'update_another_function';
// second ajax function
$.ajax( {
url: ajax_object.ajax_url,
type: 'post',
cache: true,
data: request_data,
success: function(feedback) {
},
})
}