http request with cookie in javascript
<p>I'm trying to make a request with javascript but the cookie part seem to be not working. Code I'm using is below. </p>

<pre><code>&lt;script type = "text/javascript"&gt;
     &lt;!--
        function SendReq(){
            var request = new XMLHttpRequest();
            var path="http://192.168.186.131/hello.html";
            request.onreadystatechange=state_change;

            request.open("GET", path, true);
            request.withCredentials = true;
            document.cookie="sessionid=d8e8fca2dc0f896fd7cb4cb0031ba249";
            request.setRequestHeader("User-Agent", "Mozilla/5.0");
            request.setRequestHeader("Cookie",document.cookie);
            request.setRequestHeader("Accept-encoding",'deflate');

            request.send(null);
                function state_change(){
                if (request.readyState==4){
                    alert('ready');
                    if (request.status==200){
                       alert('ok');
                    }
                else{
                alert("Problem retrieving XML data");
                }
              }
            }
     }
  &lt;/script&gt;
</code></pre>

<p>What could be the issue here? Are there better ways to get this done?</p>