Is calling twice onreadystatechange on a function possible?
<p>I have a XMLHttpRequest defined like this:</p>

<pre><code>sub_opt=function()
{
var xhr = (window.XMLHttpRequest) ? new XMLHttpRequest() : new activeXObject("Microsoft.XMLHTTP");
var data = new FormData();
...some stuff to complete data
xhr.open( 'post', 'PHP/write_and_exec_opt.php');
var display_opt=xhr.onreadystatechange = function() {
        if (xhr.readyState == 4 &amp;&amp; xhr.status == 200 ) {
                text=xhr.responseText.trim();
....some stuff
    }
xhr.send(data);
return xhr;
}
</code></pre>

<p>this function was called by another function where xhr is stored as a global var for the js file under the name previousRequest.
While the request is processing the user can do other stuff but I need some of the stuff he may have initialized to stop once the request is over. Thus I put in the necessary place the following part:</p>

<pre><code>var stop_refresh=previousRequest.onreadystatechange = function() {
        if (previousRequest.readyState == 4 ) {
clearInterval(refresh);
        }};
</code></pre>

<p>to be called when the same request is over.
The problem is that if I put only one of the onreadystatechange it works fine but with the two only thelast one work. 
Is it not allowed to do what I am trying?</p>

<p>Thank for advices.</p>