使用ajax通过邮件发送信息时出现问题


Problems sending info with ajax by post

我制作了一个审核脚本,对上下问答进行投票。以前这个脚本还可以,但当我再次回来开始这个项目的编码时,它已经不起作用了。

脚本正在做:当你点击一个名为vote的div,或者vote1一个链接时,它会询问它是向上还是向下。如果它启动了,它会加载url:"mod_up_vote.php",通过帖子发送一些关于你正在投票的问题的信息。这还可以。但现在不行。它不会加载那个页面,因为我在数据库中打印并插入$_POST变量,但什么都没有。

你认为这里出了什么问题?谢谢

   $(document).ready(function()
   {
   $(document).delegate('.vote, .vote1', '.vote2', 'click', function()
       {
   var id = $(this).attr("id");
   var name = $(this).attr("name");
   var dataString = 'id='+ id ;
   var parent = $(this);
   if(name=='mod_up')
   {
   $(this).fadeIn(200).html('<img src="dot.gif" align="absmiddle">');
   $.ajax({
      type: "POST",
      url: "mod_up_vote.php",
      dataType: "xml",
      data: dataString,
      cache: false,
      success: function(xml)
      {
   //$("#mod-pregunta").html(html);
   //$("#mod-respuesta").html(html);
   //parent.html(html);
    $(xml).find('pregunta').each(function(){
    var id = $(this).attr('id');
    var pregunta = $(this).find('preguntadato').text();
    var respuesta = $(this).find('respuestadato').text();
    var votoup = $(this).find('votoup').text();
    var votodown = $(this).find('votodown').text();
    var id_pregunta = $(this).find('id_pregunta').text();
    var id_respuesta = $(this).find('id_respuesta').text();
    $("#mod-pregunta").html(pregunta);
    $("#mod-respuesta").html(respuesta);
    //$(".vote").attr('id', $(this).find('id_pregunta').text());
    $(".vote1").html("<a href='"modera'" title='""+ id_pregunta + "-"+ id_respuesta + "-1'" class='"vote1'" id='""+ id_pregunta + "-"+ id_respuesta + "-1'" name='"mod_up'">Aceptar</a>");
    $(".vote2").html("<a href='"modera'" title='""+ id_pregunta + "-"+ id_respuesta + "-2'" class='"vote2'" id='""+ id_pregunta + "-"+ id_respuesta + "-2'" name='"mod_up'">Rechazar</a>");
    //$("span", this).html("(ID = '<b>" + this.id + "</b>')");
     });
     }  });
   }
 return false;
});

这看起来像是JQuery的一个问题。为什么使用delegate而不是click?此外,您要委托的参数似乎不正确。如果你查看文档,你会看到函数签名是:

$(elements).delegate(selector, events, data, handler);  // jQuery 1.4.3+

您正在将函数绑定到一个名为'.vote2'的事件,我只能假设它不存在。

请尝试使用click,据我所知,没有理由使用delegate。

编辑:

尝试像这样使用click

$('.vote, .vote1').click(function(){ /* your code here */ });