-1

I would like to send POST data using an html tag. I know that there is no way doing this unless i script. However i tried , but couldn't get it to work.

<a class="test" onClick="assign()"><img src='<?php echo $accounts[$i]['Account']['image']; ?>' /> <?php echo $accounts[$i]['Account']['screen_name']; ?></a>    

I tried using this:

function assign(){ 
            $.post("/Accounts/index", 
            { data: "test" 


            });
        }    

and i also tried this :

$(document).ready(function(){

            $(".test").click(function(){

                $.post("/accounts/index", 
                { data: "test"

                });
            });

        });
tshepang
  • 12,111
  • 21
  • 91
  • 136
omar.furrer
  • 285
  • 6
  • 12
  • Possible duplicate http://stackoverflow.com/questions/6060025/submit-a-form-when-click-on-a-hyperlink – 000 Jul 27 '12 at 11:34

2 Answers2

0

It may be helpful to prevent the anchor's default click action by returning false like so:

<a class="test" onClick="assign(); return false;"> ...

or like so:

...
$(".test").click(function(){
    ...
    return false;
});
site
  • 1,608
  • 14
  • 11
0

Try this :

$(".test").click(function () {
    $.ajax({ url: 'http://.....your path...../accounts/index',
        data: {test:1},
        type: 'post',
        success: function(output) {
            //your code
                 }
            }); 
});
Krishna
  • 1,540
  • 2
  • 11
  • 25