簡體   English   中英

如何將值從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....    
});

});

資訊提供ly

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM