0
function update(id, flag) {
    var flag_count = jQuery(flag + id).html();
    flag_count++;
    jQuery(flag + id).html(flag_count);
    jQuery.ajax({
        url: 'update_count.php',
        type: 'post',
        data: {
            type: flag,
            id: id
        },
        success: function(result) {

        }
    })

}

How to pass parameters in data but flag and id are arguments of the function.

How to write this?

data:'type='+flag+'&id='+id

Pls help...

isherwood
  • 58,414
  • 16
  • 114
  • 157
  • 1
    Does this answer your question? [How to pass parameters in $ajax POST?](https://stackoverflow.com/questions/18697034/how-to-pass-parameters-in-ajax-post) – OMi Shah Nov 04 '22 at 17:48

1 Answers1

0

Below there is a JavaScript approach. You normally add this function inside your function, the same way as you do with jQuery.

xmlhttp.onreadystatechange = function ()
    {
        if (this.readyState === 4 && this.status === 200)
        {
            if (confirm == 9 || confirm == 10) 
            {
                // do something prior to send data to ajax file
            }
        }
    };
    xmlhttp.open('POST', 'update_count.php?type=' + flag + '&id=' + id, true);
    xmlhttp.send();

The above code will pass the values stored inside each variable (flag, id) to the ajax file (update_count.php).