简体   繁体   English

如何合并这些代码

[英]How can I combine this codes

In the following code i am trying to make a post report system using Jquery ajax and php. 在下面的代码中,我试图使用Jquery ajax和php创建一个后报告系统。 When you click the .reportit button of a post, you have to get the post id and then show popup form, and then when pressing the .report button of this form, you have to execute the ajax after getting the id of the post and other information that will be sended to report_send_ajax.php . 当您单击帖子的.reportit按钮时,您必须获取帖子ID,然后显示弹出表单,然后在按下此表单的.report按钮时,必须在获取帖子的ID后执行ajax,其他信息将发送到report_send_ajax.php

How can I combine the following code to do it? 如何结合以下代码来做到这一点?

$('.reportit').click(function(){
  var i = $('.sikayet-et-alani').attr('id', $('.reportit').attr('id'));
   $.ajax({
      type: "POST",
     url: 'report_send_ajax.php',
     data: i,
     beforeSend: function(){$("#posting").html('<img src="icons/ajaxloader.gif"/>'); },
     success: function(html) {
     //Do Something
   }
}); 
});

with this code: 使用此代码:

$(document).ready(function(){
        $('.reportit').click(function(){
          $('.vduzalani').animate({'opacity':'.50'}, 300, 'linear');
          $('.sikayet-et-alani').animate({'opacity':'1.00'}, 300, 'linear');
          $('.vduzalani, .sikayet-et-alani').css('display', 'block');
        });

        $('.close').click(function(){
          close_box();
        });
        });

      function close_box()
      {
        $('.vduzalani, .sikayet-et-alani').animate({'opacity':'0'}, 300, 'linear', function(){
          $('.vduzalani, .sikayet-et-alani').css('display', 'none');
        });
      }

This is the JavaScript DEMO from codepen.io 这是来自codepen.io的JavaScript DEMO

try this 尝试这个

$(document).ready(function(){
    var i;
    $('.reportit').click(function(){
        $('.vduzalani').animate({'opacity':'.50'}, 300, 'linear');
        $('.sikayet-et-alani').animate({'opacity':'1.00'}, 300, 'linear');
        $('.vduzalani, .sikayet-et-alani').css('display', 'block');
        //get id
        i = $(this).attr('id');


    });
    //click .report button
    $('.bildir').click(function(e){
        e.preventDefault();
        $.ajax({
            type: "POST",
            url: 'report_send_ajax.php',
            data: {id:i, sikayet_bildirimi:$('input[name="sikayet_bildirimi"]:checked').val()},
            beforeSend: function(){$("#posting").html('<img src="icons/ajaxloader.gif"/>'); },
            success: function(html) {
            //Do Something
            }
        });
      return false;
    });
    $('.close').click(function(){
        close_box();
    });
});

function close_box()
{
    $('.vduzalani, .sikayet-et-alani').animate({'opacity':'0'}, 300, 'linear', function(){
        $('.vduzalani, .sikayet-et-alani').css('display', 'none');
    });
    $('input[name="sikayet_bildirimi"]').attr('checked',false);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM