如何从href链接传递值到ajax函数


how to pass value from href link to ajax function

我需要呼叫ajax function…发送值......由href link…但没有通过url .....我需要打印内容....这些内容来自于数据库。所以我使用ajax..........

我的ajax函数

$(document).ready(function () {
    show_customize_image = function () {
        alert('test');
        $.ajax({
            type: "POST",
            url: ajax_url_store,
            data: {
                action: 'store',
                views: JSON.stringify(thsirtDesigner.getProduct())
            },
            success: function (data) {
                if (parseInt(data) > 0) {
                    $("#cart_pd").submit();
                }
            },
            error: function () {
                //alert('some error has occured...');
            },
            start: function () {
                //alert('ajax has been started...');    
            }
        });
    }
});

html

<td class="center">
    < a href="javascript:;" onclick="show_customize_image('<?php echo $pageVal['customers_id'];?>');">Delete
        < /a>
</td>

这个解决方案怎么样?

<table>
<thead>
    <th>Col</th>
    <th>Col</th>
</thead>
<tbody>
    <tr>
        <td>bla</td>
        <td class="center"> <a href="javascript:void();" class="tdelete" data="<?php echo $pageVal['customers_id'];?>">Delete</a>
        </td>
    </tr>
</tbody>

$(document).ready(function () {
$(".tdelete").on("click",function(e){
    e.preventDefault();
    var varFromPhp = $(this).attr("data"));
    //ajax request....    
});

});

feedly