Let’s say I have this code which gets the latest posts via ajax:
$.ajax({
url: loadmore,
data: {lastid: lastid,mode:'latest'},
dataType: 'json',
type: 'POST',
timeout: 10000,
success: function(json){
//some code
},
error: function(jqXHR, textStatus, errorThrown){
//some code
}
});
How do I change the content of the data? Here’s my try but something failed.
$.ajax({
url: loadmore,
if($('.postlist').hasClass('best'))
data: {lastrank: lastrank,mode: 'best'},
else
data: {lastid: lastid,mode:'latest'},
dataType: 'json',
type: 'POST',
timeout: 10000,
success: function(json){
//some code
},
error: function(jqXHR, textStatus, errorThrown){
//some code
}
});
Ternary operator: