2017-08-13 67 views
0

我在Ajax很新。我想用沒有FORM的AJAX發送數據。我嘗試了<a>,但它沒有奏效。該示例中可能缺少一些內容。一切正常,但價值不發送。如何通過AJAX類型GET發送值?

HTML & PHP代碼

<?php 
$mail = $_GET['mail']; 
$lists = mysql_query("SELECT id FROM customers WHERE mail='$mail'"); 
while($list = mysql_fetch_array($lists)) 
{ 
    $id = $list['id']; 
    echo ' 
     <tr> 
      <td style="text-align:center;">'.$id.'</td> 
      <td style="text-align:center;"> 
       <a id="delete" value="'.$id.'" style="cursor:pointer;" title="Delete This"> 
        <span class="table-icon"> 
         <i class="mdi mdi-close"></i> 
        </span> 
       </a> 
      </td> 
     </tr> 
    '; 
} 
?> 
<div class="mdl" id="alertmodal"><div class="mdl-container"><div class="postMessage" align="center"></div></div><div class="mdl-close" data-target="#alertmodal"></div></div> 
<a class="btn" id="confirm" data-type="confirm" data-fullscreen="false" data-overlayClick="true"></a> 

Ajax代碼

$(function(){ 
    $(".mdl-close").on('click',function(){ 
     mdl_close("#alertmodal"); 
     window.location.href = 'delete.php'; 
    }); 
    $('#confirm').mdl({ 
     content:"Are you sure?" 
    }, function(result){ 
     if(result==true) 
     { 
      $.ajax({ 
       url: 'deletethis.php', 
       type: 'GET', 
       dataType: "json", 
       data: {id: $('#delete').val(),}, 
       success: function(result){ 
        $(".postMessage").html(result.Message); 
        mdl_open("#alertmodal"); 
       } 
      }); 
     } 

    }); 
    $("#delete").on('click',function(e) { 
     $("#confirm").trigger("click"); 
     e.preventDefault(); 
    }); 
}); 

我可以使用什麼的<a>之外?

回答

0

嘗試替換data: {id: $('#delete').val(),},data: {id: $('#delete').attr('value'),},

+0

謝謝。有效。 –