title: Load img src via Jquery ajax call
body: <p>I have an img control/element on my asp.net page.</p>
  
  <p>At the moment i am call an ashx handler to retrn a byte array using context type as:</p>
  
  <pre><code>context.Response.ContentType = "image/jpg";
  </code></pre>
  
  <p>The javascript sets the image like this:</p>
  
  <pre><code>img.src = url + '/Mobile/GetFrame.ashx?';
  </code></pre>
  
  <p>Is there a way to do the same but using a JQuery/Ajax call instead?</p>
  
  <p>So, for instance:</p>
  
  <pre><code>function GetImage() {
      $.ajax({
          url: url + '/Mobile/GetFrame.ashx',
          type: 'GET',
          timeout: freshWaitlimit,
          data: lastTS,
          success: function (response, status, xhr) {
              serverImage1x4.src = response;
          },
          error: function (jqXHR, textStatus, errorThrown) {
              alert('err');
              finished = true;
          }
      });
  }
  </code></pre>
  
  <p>But I get no image.  But i get no error either..</p>
  
  <p>I have my solution but it really is not all my own work. Here it is:</p>
  
  <pre><code>function GetImage() {
      var xmlHTTP = new XMLHttpRequest();
      xmlHTTP.open('GET', url + '/Mobile/LiveXP.ashx?Alias=' + Alias + '&amp;camIndex=' + camIndex + '&amp;Guid=' + createGuid(), true);
      xmlHTTP.responseType = 'arraybuffer';
      xmlHTTP.timeout = 10000;
      xmlHTTP.ontimeout = function () { alert("Timed out!!!"); finished = true; }
      xmlHTTP.onload = function (e) {
          var arr = new Uint8Array(this.response);
          var raw = String.fromCharCode.apply(null, arr);
          var b64 = btoa(raw);
          var dataURL = "data:image/jpeg;base64," + b64;
          serverImage1x4.src = dataURL;
      };
      xmlHTTP.send();
  }
  </code></pre>