Search code examples
javascripthttphttp-postdom-events

Javascript POST hook


I've got an web page up and running, and I'm wondering if it is possible to make an event listener that gets all of the HTTP POST or GET or PUT events. So, what I want to do is when the user clicks a submit button on my website or clicks on a link, a Javascript function is triggered so that I can get the params in the http request.

What I want to do is check the parameters from an http request and under certain conditions send another, different http request.


Solution

  • You could add an event handler to all of your forms and links on the page:

    var myHandler = function(e) {
    // Do what you want here
    };
    
    $('a').click(myHandler);
    $('form').submit(myHandler);