简体   繁体   English

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

[英]how to pass value from href link to ajax function

I need to call ajax function ...and send value...... by href link ... but without passing by url ..... I need to print content ....and that content come's form database... So i'm using ajax.......... 我需要调用ajax function ...并通过href link发送值...但不通过url传递.....我需要打印内容..并且该内容来自表单数据库。 ..所以我正在使用ajax ..........

my ajax function 我的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...');    
            }
        });
    }
});

my html 我的HTML

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

What about this solution? 那这个解决方案呢?

<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 资讯提供ly

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM