Guide to utilizing the .NET MVC FileContentResult to send an image through Ajax

I recently created a website using the .net MVC framework, and one of the views contains an image with the src attribute referring to an action called Render. Here is an example:

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

Everything was working perfectly fine until the URL size exceeded its limits. I had no choice but to switch to using a POST request via AJAX. I attempted to use XMLHttpRequest and assign responseXML to the img's src attribute, but unfortunately, it did not work as expected.

Any suggestions on what steps should I take next?

Answer №1

Consider experimenting with using a Base64 encoded version of the image

Converting an image path to a base64 string

Information on embedding Base64 images

The issue you may be facing is that the XMLHttpRequest object only permits text responses and not binary ones

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Using jQuery to select the child element of the parent that came before

Recently, I've been experimenting with creating animations using CSS and jQuery. While it has been successful so far, I'm now looking to take it a step further. Specifically, I want information to appear on top of an image when the user clicks on ...

A JavaScript popup displaying selectable options and a callback function

Is there a feature in Javascript that is similar to Java's alert builder? I need a button that, when clicked, will display an alert with various options. When an option is selected, it should trigger a callback function passing the chosen option along ...

Guide on transferring selected table row using checkbox in HTML and sending the information to views.py file in Django

Hi there, I'm new to Python-Django and in need of help. I want to be able to pass the selected table row from a template to views.py with checkboxes checked using the POST method. Additionally, I would like to be able to select multiple rows. After su ...

Retrieve the chosen option value from the foundation dropdown menu

I have been exploring the functionality of Foundation drop-downs. To see it in action, visit this link: Below is the code I used to create a dropdown: <a href="#" data-dropdown="drop1" >Date Range </a> <ul id="drop1" class="f-dropdow ...

"Exciting developments in Angular 17 with the introduction of the new @

I need to output elements from an array of strings starting at index 1. arr = [ "str1", "str2", "str3", "str4", "str5" ] The desired output is: str2 str3 str4 str5 To achieve this, use a new @for loop in ...

Automatically load file and play audio when the page is loaded

I have created code that allows me to input an mp3 file, output the audio, and display a visual representation of the music. Currently, loading the file is done manually through an input type="file". Now, I want to change it so that the music automaticall ...

jQuery-chosen - Transfer custom attribute from chosen option to list when selected

I have a selection list as shown below: <select data-placeholder="Choose users" style="width:350px;" multiple class="chosen-select" tabindex="8"> <option data-user-id="1">User1</option> <option data-user-id="3">User2</op ...

Unlocking the Power of Javascript Promises in FileReader

I am facing an issue with my code. Here is the HTML snippet: <input type='file' multiple> And this is my JavaScript code: var inputFiles = document.getElementsByTagName("input")[0]; inputFiles.onchange = function(){ var fr = new File ...

Results are returned out of order when an AJAX request is made within a for loop

I'm attempting to insert 10 images into my #container in the order they are requested, but for some unknown reason, they are not displayed in the correct sequence. Currently, I am obtaining the URLs through a for loop and passing them into an AJAX re ...

Having trouble dynamically adding HTML elements in JQuery

I am dynamically adding HTML elements during runtime using an AJAX call from a JavaScript file. Currently, I am attempting to use a combo box drop-down element to display a list of data. Here is how I am trying to achieve this in my script: $("#myList") ...

Encountering issues with the Struts 2 application for logging in and out

Exploring ways to prevent a logged-out user from easily logging back in using Struts 2 Are there any additional technologies or strategies that can be implemented? Looking for sample code and solutions on how to address this issue Struggling with sessio ...

"Which is better for maximizing the efficiency of an image grid: CSS or Jquery? What are the key

As a UX Designer looking to enhance my coding skills, I must admit my code may not be perfect. Please bear with me as I navigate through this process. I am in the process of revamping my portfolio website. The original seamless grid was created using a Ma ...

"Oops, it seems like there are an excessive number of connections in Express MySQL causing

While programming in Angular and creating an API server in Express, I encountered a minor issue after spending hours coding and making requests to the API. The problem arises when the maximum number of requests is reached, resulting in an error. Everythin ...

Ways to avoid storing repeating paragraphs in JavaScript Array?

Can someone help me with my code? I am struggling to prevent duplicate data from being saved into an array. When I click on any two paragraph elements, the text inside them gets added to an array named `test`. However, I want to avoid saving the same tex ...

firefox compatibility issues with jquery ajax

Trying to establish a connection with a URL and expecting a large object in response has proven to be challenging. The process appears to function smoothly until an error occurs during the return reply, triggering the .ajax.error() function. Unfortunately, ...

What is the best method for initializing a grid combo box value using JavaScript?

How do I set the value of a combobox in a grid itemtemplate using JavaScript? <telerik:GridTemplateColumn AutoPostBackOnFilter="true" CurrentFilterFunction="Contains" DataField="FAULT" FilterControlWidth="100%" ...

Manipulate the CSS of Quasar components within a child component in VueJS

Currently, I am incorporating Quasar components into my VueJS application in order to create an app. Within this setup, I have a child component that is being imported into a parent component. To customize the child component's appearance, I have over ...

What is the process for including a new item in the p-breadcrumb list?

Having trouble getting my code to add a new item to the p-breadcrumb list on click. Any assistance would be greatly appreciated. Thank you in advance! Check out the live demo here ngOnInit() { this.items = [ {label: 'Computer'}, ...

What is the best way to implement the populate method in Node.js when working with MongoDB?

Here is the code snippet I am working with: const Order = require('../../models/order'); const Product = require('../../models/product'); Order.find({}, '_id product quantity', function(err, result) { if (result) { con ...

Is there a way to customize setInterval for a specific element?

For some time now, I've been working on creating a typing animation that triggers when links come into view during scrolling. However, I've encountered a problem with jQuery not selecting the correct element or the setInterval objects causing all ...