使用 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); } }); }); });
广告