2016-11-11 61 views
-1

a-link在index.php中工作。但是,如果a-link來自ajax響應,A-link不起作用,我想通過響應a-link來調用相同的功能。這裏是我的完整代碼。請用完整的代碼解釋。如何通過ajax響應鏈接調用相同的功能

的index.php

<html> 
<head> 
<script type="text/javascript" src="http://code.jquery.com/jquery.js"></script> 
<script> 
$(document).ready(function(){ 
     function SelRej(){ 
     var SRvalue = $(this).attr("value"); 
     //alert(SRvalue); 

     var URL = "Ajax.php"; 
     $("#"+SRvalue).load(URL, { 
      "SRvalue":SRvalue 
      }); 

     if(SRvalue=="Reject"){$("#Select").html("<a href='#' class='Select' value='Select'>Select</a>");} 
     if(SRvalue=="Select"){$("#Reject").html("<a href='#' class='Reject' value='Reject'>Reject</a>");} 
     return false; 
     } 

     $(".Select").on('click', SelRej); 
     $(".Reject").on('click', SelRej); 
    }); 
</script> 
</head> 
<body> 
<div id="Select"><a href='#' class='Select' value="Select">Select</a></div> 
<div id="Reject"><a href='#' class='Reject' value="Reject">Reject</a></div> 
</body> 
</html> 

Ajax.php

<?php 
if($_REQUEST["SRvalue"]){ 

    $SRvalue = $_REQUEST['SRvalue']; 
    if($SRvalue=="Select"){echo "Selected";} 
    if($SRvalue=="Reject"){echo "Rejected";} 
} 
?> 

回答

0

就是這樣我一直在尋找

<html> 
    <head> 
    <script type="text/javascript" src="http://code.jquery.com/jquery.js"></script> 
    <script> 
    $(document).ready(function(){ 

     function SelRej(){ 
      var SRvalue = $(this).attr("value");//alert(SRvalue); 
      $.ajax({ 
       url: "Ajax1.php", 
       cache: false, 
       method: "GET", 
       data: {SRvalue: SRvalue} 
       }).done(function(response) { 
       var splitted = response.split("|"); 
       $("#Select").html(splitted[0]); //alert(splitted[0]); 
       $("#Reject").html(splitted[1]); //alert(splitted[1]); 
      }); 
     } 
      //$(".Select").on('click', SelRej); 
      //$(".Reject").on('click', SelRej); 

      $("body").on('click', ".Select", SelRej); 
      $("body").on('click', ".Reject", SelRej); 


    }); 
    </script> 
    </`head`> 
    <body> 
    <div id="Select"><a href='#' class='Select' value="Select">Select</a></div> 
    <div id="Reject"><a href='#' class='Reject' value="Reject">Reject</a></div> 
    </body> 
    </html> 

Ajax1.php

<?php 
if($_REQUEST["SRvalue"]){ 

    $SRvalue = $_REQUEST['SRvalue']; 
    if($SRvalue=="Select") 
    { 
    echo "Selected|<a href='#' class='Reject' value='Reject'>Reject</a>"; 
    } 

else if($SRvalue=="Reject") 
    { 
    echo "<a href='#' class='Select' value='Select'>Select</a>|Rejected"; 
    } 
} 

?>