views:

161

answers:

2

Hi, I need to insert/update data by using link or image

I need a code how to call post data using jquery !

< a href="some.asp" onClick="someaction, value to send" > Link

Please help

+1  A: 

HTML

<a href="some.asp" class="upload">Link</a>
<input type="hidden" name="parameter" value="value-to-send" />

Code

$(function() {
    $('.upload').click( function() {
         $.post( $(this).attr('href'),
                 $(this).next('input[type=hidden]').serialize(),
                 function(data) { do something with returned data } );
         return false;  // cancel link default action
    });
});

You might also want to check out the documentation at jQuery.com, especially the section on How jQuery Works.

tvanfosson
+1  A: 

Have a look in the Jquery-Documentation and change the function call by attaching the trigger later, so that it looks this-alike:

HTML:

<a id="myid" href="javascript:void(0);">My link</a>
<div id="result"></div>

Code:

    $("#myid").click(function() {
        $.ajax({
         type: 'POST',
         url: 'some.asp',
         success: function(result) {
          if(result != "false") {
           $("#result").html(result); 
          } 
         }
          }) 
    });

(untested)

schneck
But each link has diffrent valuelike this <a href="#" onclick="$.post('test.asp', { profiid: '<%=(Recordset1.Fields.Item("ProfileID").Value)%>', seenby: '<%= Session("Username") %>' } );">Remove </a>
Dev
then wrap it in a function: see here: http://stackoverflow.com/questions/370359/passing-parameters-to-a-jquery-function
schneck