samedi 9 juillet 2016

How onclick can post to a new page?


How may I have a tag <a> to onclick go to a new page and POST something?

I have the code below:

<a href="#" onclick="cat_filter(1);">Cat Name</a>

And the function cat_filter()

function cat_filter(cat) {

    jQuery.ajax({
      'url': 'http://xxx/procurar', 
      'type': 'POST',
      'dataType': 'json', 
      'data': {cat: cat}
    });

}

PHP on URL page

$cat = $_POST['cat´];

What I neeed to do is to execute the function cat_filter() to pass the variable to a new URL as POST. How may I achieve this?


Aucun commentaire:

Enregistrer un commentaire