使用 PHP 中的 ajax 傳送多條資料
資料可以透過 JSON 或透過常規 POST 傳送。以下是透過 JSON 傳送資料的示例 −
var value_1 = 1;
var value_2 = 2;
var value_3 = 3;
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "your_url_goes_here",
data: { data_1: value_1, data_2: value_2, data_3: value_3 },
success: function (result) {
// perform operations here
}
});使用常規 post,可以使用以下程式碼 −
$.ajax({
type: "POST",
url: $('form').attr("action"),
data: $('#form0').serialize(),
success: function (result) {
// perform operations here
}
});上面程式碼的替代方法如下所示 −
data:'id='+ID & 'user_id=' + USERID,
with:
data: {id:ID, user_id:USERID}
so your code will look like this :
$(document).ready(function(){
$(document).on('click','.show_more',function(){
var ID = 10;
var USERID =1;
$('.show_more').hide();
$('.loding').show();
$.ajax({
type:'POST',
url:'/ajaxload.php',
data: {id:ID, user_id:USERID},
success:function(html){
$('#show_more_main'+ID).remove();
$('.post_list').append(html);
}
});
});
});
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP