使用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 } });
正常发布后,可以使用以下代码-
$.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); } }); }); });