ajax - Passing post parameters with jQuery.post -


i have regular anchor tag bound $.post() i'm having trouble wrapping head around best way pass along parameters. here's i've got:

<a  href="ajax/tag_delete.php?id=<?php echo $tag->id;?>" <!-- feels "get" , don't want have parse query string --> id="<?php echo $tag->id;?>" <!-- feels wrong, shouldn't have number id  -->  class="delete_tag_btn"> delete </a>  <script>     $('.delete_tag_btn').bind('click', function(event){         event.preventdefault();         $.post( this.href, {/* best way these */}, function(reply) {             log(reply);         });     }); </scirpt> 

any appreciated. thanks.

$(this).attr('href').split('=')[1]

of course, that's dependent on url having single querystring parameter. if needed, can little more fancy, solves immediate problem.

edit:

$(document).ready(function(){     $('.delete_tag_btn').bind('click', function(event){         event.preventdefault();          var s = $(this).attr('href').split('?')[1].split('&');         var = new object();          for(var n = 0; n < s.length; ++n)         {             var t = s[n].split('=');             console.log(string(t[0]));             a[string(t[0])] = t[1];         }          console.log(a);     }); }); 

given edit, can specify number of attributes in href, passed post. in other words, can use function anywhere throughout application , don't need specify keys get:

$.post(       this.href,       data: a,       function(reply) {             log(reply); }); 

Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -