0

I built a website using .net MVC, and there is an img in the view. And the attribute src refer to an action Render, just like this:

<img src="XXX/render?..." />
public ActionResult Render()
{
   return new FileContentResult(byte[], "jpg"); // just like this
}

Thus, it works well and the "img" displays correctly. But now the url size is over limits. So I have to use Post request by ajax. And I use the XMLHttpRequest and assign the responseXML to the img's src . And it doesn't work.

What should I do?

joan16v
  • 5,055
  • 4
  • 49
  • 49
majing
  • 25
  • 5

1 Answers1

0

You might want to try returning a Base64 encoded image

Convert image path to base64 string

Embedding Base64 Images

I believe the problem you're encountering is that the XMLHttpRequest object only supports text responses and not binary

Community
  • 1
  • 1
Josh Russo
  • 3,080
  • 2
  • 41
  • 62
  • 1
    "XMLHttpRequest object only supports text responses and not binary" Not stricly true anymore, as [this Mozilla Developer Network](https://developer.mozilla.org/en/docs/Web/API/XMLHttpRequest/Using_XMLHttpRequest#Handling_binary_data) article explains. – Jason Evans Nov 11 '15 at 14:29
  • This is true and I should have mentioned it. I generally disregard it because IE 9 doesn't support binary responses. This fact prevents most people from being able to take advantage of the feature – Josh Russo Nov 11 '15 at 15:08