下面的代码将item的id发送到more.php以加载更多内容。它工作正常。现在要添加更多功能,我需要通过相同的代码向more.php发送一个更多的id。
public class Address
{
public string City { get; set; }
public string Street { get; set; }
}
public class User
{
public Address Address1 { get; set; }
public Address Address2 { get; set; }
}
public class DefaultAddressSortingSpecification<TEntity>
{
private readonly Expression<Func<TEntity, Address>> _keySelector;
public DefaultAddressSortingSpecification(Expression<Func<TEntity, Address>> keySelector)
{
_keySelector = keySelector;
}
public IQueryable<TEntity> OrderingEntitiesFrom(IQueryable<TEntity> query)
{
//order by city
//order by street
}
}
usage:
var s1 = new DefaultAddressSortingSpecification<User>(user => user.Address1);
var s2 = new DefaultAddressSortingSpecification<User>(user => user.Address2);
假设第二个ID为<script type="text/javascript">
$(document).ready(function(){
$(document).on('click','.show_more',function(){
var ID = $(this).attr('id');
$('.show_more').hide();
$('.loding').show();
$.ajax({
type:'POST',
url:'more.php',
data:'id='+ID,
success:function(html){
$('#show_more_main'+ID).remove();
$('.display').append(html);
}
});
});
});
</script>
,如何通过相同的ajax代码发送此var catid = '<?php echo $cat ?>';
。 catid
是我应该做的事情,但是当我的数据载有data : {id : id, catid : catid}
时,无法知道如何处理当前情况。
答案 0 :(得分:1)
<script type="text/javascript">
$(document).ready(function () {
$(document).on('click', '.show_more', function () {
var ID = $(this).attr('id');
$('.show_more').hide();
$('.loding').show();
$.ajax({
type: 'POST',
url: 'more.php',
data: { id:ID, userid: userid },
success: function (html) {
$('#show_more_main' + ID).remove();
$('.display').append(html);
}
});
});
});
答案 1 :(得分:0)
要检索多个输入,我建议将它们组合在一个表单中:
首先将您的输入嵌入带有提交按钮的表单中,您也不应该使用相同的名称两次,因为它现在不起作用,创建唯一的名称
<form action="GET" id="myForm">
<input id="string" type="text" name="string" />
<input id="string2" type="text" name="string" />
<input type="submit" value="Go" />
</form>
并编写代码以提交ajax方式
$('#myForm').submit(function(event) {
// Stop form from submitting normally
event.preventDefault();
var $form = $(this);
$.ajax({
type: "GET",
url: "retrieve.php",
data: $form.serialize(), //make it JSON
success: function() {
console.log("it worked");
}
});
});