0
在JQuery Ajax調用中,推薦使用以下哪些參數?我知道兩者都很相似,但這兩者之間有明顯的優勢嗎?Ajax - url參數與數據
使用URL參數調用Ajax。
$.ajax({
url: 'test.php?uAction=action&uType=type',
dataType: 'json',
success: function(data, status){
$.each(data, function(i,item){
});
},
error: function(){
output.text('There was an error loading the data.');
}
});
或Ajax調用與參數排列對象
$.ajax({
url: 'test.php',
dataType: 'json',
data: {
uAction: 'action',
uType: 'type'
},
success: function(data, status){
$.each(data, function(i,item){
});
},
error: function(){
output.text('There was an error loading the data.');
}
});
我更喜歡第二種方法,因爲我不必擔心URL編碼鍵和值 – Phil