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

时间:2014-07-09 07:08:07

标签: javascript php jquery html ajax

我需要致电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>

1 个答案:

答案 0 :(得分:2)

这个解决方案怎么样?

<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