使用AJAX传递多个参数。价值来自DIV

时间:2012-04-23 23:50:16

标签: ajax

我试图通过两个参数认为ajax。我从中提取的变量是在div中,并且是在运行中完成的。我可以轻松传递date_time但我还需要能够传递变量“id”。日期位于正在加载和更改的数组中。此页面的ID不会更改。

这是javascript。下面将是我的div。所有追加此操作的尝试都失败了。有什么想法吗?

<div class='letter' width=600  date_time=\"$date_time\" id=\"$id\">
....doing stuff here.....
</div>

function OnScrollLetters () {  var div = document.getElementById ("userLetter");
   var info = document.getElementById ("info");
   if(div.scrollTop == (div.scrollHeight - div.clientHeight))
   {    
      $('div#loadMoreComments').show();
      $.ajax({
         url: "get_letters_for_profile_scroll.php?lastComment="+ $(".letter:last").attr('date_time'),
         success: function(html) {
            if(html){       
               $("#userLetter").append(html);
               $('div#loadMoreComments').hide();
            }else{
               $('div#loadMoreComments').replaceWith("<center><h1 style='color:red'>End of Letters</h1></center>");
            }
         }
      });
   }
}

这是我的div。

<div class='letter' width=600  date_time=\"$date_time\" id=\"$id\">
....doing stuff here.....
</div>

1 个答案:

答案 0 :(得分:0)

尝试在参数名称和值

之间放置一个“=”
..."&id="+$(".letter:last").attr('id')