title: Browser requests file, server downloads pdf, browser displays pdf in iframe
body: <p>this is what I want to do:
  1) a browser initiates an ajax request to the server, asking for a pdf.
  2) the server downloads the pdf, and returns the pdf for display.
  3) the browser displays the downloaded pdf in a pre-existing iframe.</p>
  
  <p>Below is my code. It appears to stop at the iframe part, but I suspect that its not sending the pdf properly. </p>
  
  <p>Browser index.html file:</p>
  
  <pre><code>var uri = '/viewer/loaddrawing/';
  $.getJSON(uri, {key:value}, function(data, jqXHR){
      document.getElementById("iframetitle").src = uri;               
  });
  </code></pre>
  
  <p>Django server views.py file:</p>
  
  <pre><code>import requests
  def loaddrawing(request):
      value = request.GET.get('key')
      #the key is used to generate a unique url, but for test purposes lets use the url shown below
      url = "http://cbmeturkey.com/media/109/test.pdf"
       response = urllib2.urlopen(url)
       some_data = response.read()
      return HttpResponse(some_data, mimetype='application/pdf')
  </code></pre>
  
  <p>EDIT:</p>
  
  <p>I have one issue remaining: I don't want to use the below code in my index.html file anyway, because I want to actually download the pdf and use it again. The reason for this is that my index.html page uses javascript to display and hide the iframe, and with the below code the pdf is redownloaded each time the iframe is shown.</p>
  
  <pre><code>var uri = '/viewer/loaddrawing/';
  document.getElementById('iframetitle').src = uri + '?key=' + value;
  </code></pre>
  
  <p>SOLVED:
  The above issue was solved after directions from Augusto, and the following index.html code, which loads the pdf only once, although notice that now I am now modifying a div (named "divtitle") and not an iframe:</p>
  
  <pre><code>var uri = '/viewer/loaddrawing/' + '?key=' + value;
  var htm = '\&lt;iframe src="' + uri +'" onload="downloadComplete()"&gt;\&lt;/iframe&gt;';
  document.getElementById('divtitle').innerHTML = htm;
  </code></pre>