创建一个启动PHP代码的jQuery事件处理程序


Creating a jQuery event handler that initiates PHP code

我要做的是创建一些jQuery代码,这些代码将启动一些PHP代码,并在单击图像时重新加载页面。我已经创建了下面的代码,但对于jQuery中启动PHP代码所需的事件处理程序类型感到困惑。我怀疑这是AJAX的临界点,但它是同步的。这是下面的代码。

<script src="http://code.jquery.com/jquery-latest.js"></script>
<style>
img:hover { border:1px solid #021a40; margin: 1px; padding: 1px; color: #000000; 
cursor:pointer;};
</style>
<script>
$(document).ready(function(){
$('img').on('click',"img",function(){
$(this).slideUp();
What do I put here?????
});
});
</script> 
<img  src="image.gif" width="50" height="50" />

不使用ajax尝试:

$(document).ready(function()
{
   $('img').on('click',"img",function()
   {
       $(this).slideUp('slow',function () 
       {
          window.location = "url/to/phpfile.php?data="+yourdata
       });
   });
});

然后在php文件中,进行更新并输出或重定向到另一个页面。

关于上面的评论,slideUp()的第二个参数是动画完成后的回调函数,因此您应该在页面转换之前获得视觉反馈。

以下是我认为你可以做的。

$(document).ready(function(){
  $('img').on('click',"img",function(){
   $(this).slideUp('slow',function () {
      $.ajax({/* your ajax call here will run when the sliding is done */})
   });
  });
});