send data over link to jquery function -
what want
<a href="#" onclick="myjqueryfunc(data1,data2)"></a>
and in jquery
myjqueryfunc(variable1,variable2) { var formdata = "name=variable1&age=variable2"; $.ajax({ url : "ajax_post_url", type: "post", data : formdata, success: function(data, textstatus, jqxhr) { } }
so how can ?
<a href="#" data-name="x" data-age="12" id="smth"></a>
in js
$("#smth").click(function(){ var name=$(this).data('name'); var age=$(this).data('age'); $.ajax({ ... data : { var1 :name , var2:age }, ... }); });
Comments
Post a Comment