如何使用AJAX类型GET发送值?

时间:2017-08-13 11:59:38

标签: jquery ajax

我是Ajax的新手。我想用AJAX发送数据而没有FORM。我尝试了<a>,但它没有用。示例中可能缺少某些内容。一切正常,但价值没有发送。

HTML&amp; 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>之外使用什么?

1 个答案:

答案 0 :(得分:0)

尝试将data: {id: $('#delete').val(),},替换为data: {id: $('#delete').attr('value'),},