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

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -