Error in AJAX POST: base64 string formatting issue

Struggling with making an AJAX POST successfully upload and retrieve a base64 string to/from my SQL database. Upon receiving the string from the database via AJAX, it appears to be the same base64 string, but with random line breaks that render it non-functional.

In the console, the top shows the incorrectly formatted base64, while the bottom displays it correctly.

View the Photo Here

Upon inspecting the base64 string in the SQL database, it appears to be incorrectly formatted, indicating a potential issue with the initial AJAX upload. The SQL datatype is set to MEDIUMTEXT, but changing it did not affect the outcome.

// Retrieving the base64 string
let canvas = picCheckIn.getContext("2d")
let dataURL = canvas.canvas.img.src
// Hard-coding the base64 string into the image's source
imgPreviousIn.src="data:image/jpeg;base64,/9j/4A...<Rest of base64 string>"

// Assigning the AJAX base64 string to the image source
let req = Ajax(<POST query here...>)
let results = JSON.parse(req.responseText)
imgPreviousIn.src=results[0][0]

Encountering the following error code:

GET data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/4gKgSUNDX1... net::ERR_INVALID_URL

Answer №1

The issue stemmed from the SQL database. Somehow, the database was replacing plus signs with whitespace, resulting in the removal of the plus signs altogether.

To solve this problem, I implemented the use of

string.replaceAll("+","%2B")
prior to transmitting the string through an AJAX request. Additionally, I discovered that running individual AJAX calls for each string being utilized yielded the most effective results.

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

Creating a Sudoku game board using underscore templates

Currently, I am in the process of constructing a Sudoku board using underscores templating. However, I have hit a roadblock when it comes to tackling the mathematical aspects necessary for deriving the table structure. My approach involves utilizing a 1d ...

Using Selenium 2 to dynamically insert CSS styles into the currently visible webpage

I experimented with using jQuery on a webpage that has already been modified by jQuery in order to add custom CSS code: jQuery('head').append('<style type=\"text/css\">body { background: #000; }</style>'); When I ...

React: Incorporating .map for nested arrays. Ensure each child component within the list is assigned a distinct "key" property

I have an array called navMenuItems that contains data for building a navigation menu with links and link names. Each item in the array may also contain child links, similar to the mobile menu on https://www.w3schools.com/. However, I'm encountering a ...

Using InputAdornment with MUI AutoComplete causes the options list to disappear

I created a custom AutoComplete component with the following structure: https://i.sstatic.net/xcv9y.png <Autocomplete freeSolo size="small" id="filter-locks-autocomplete" options={json_list ? json_list : []} groupBy={(optio ...

Converting CSV files from Pandas to JSON format

I am trying to modify this code to get a different result parser.add_argument('-f', '--fields', help='csv fields', type=lambda s: [str(item) for item in s.split(',')]) fields = parser.parse_args().fields print(fields ...

How to retrieve a JSON value without a key using jQuery

I am struggling to fetch JSON using jQuery. If anyone can help me figure out the mistake in my code that would be greatly appreciated. The data.json file contains { "value1", "value2", "value3", "value4" } Here is my jQuery code $.getJSON( "data.js ...

Displaying a message when there are no results in Vue.js using transition-group and encountering the error message "children must be keyed

Utilizing vue.js, I crafted a small data filter tool that boasts sleek transitions for added flair. However, I encountered an issue with displaying a message when there are no results matching the current filters. Here's what I attempted: <transit ...

I'm puzzled by this error message: "Uncaught TypeError: Cannot read property 'insertAdjacentHTML' of null at renderHTML". Can anyone help me figure out what

I am struggling to get my information to render properly without displaying any errors. I followed a tutorial video, but I am encountering several console errors that may be impacting the rendering process. var bitprice = document.getElementById('b ...

What is the best way to determine the total number of rows that include a specific value?

Using AngularJS, I have a table that is populated with data using the ng-repeat directive. Here is an example: http://jsfiddle.net/sso3ktz4/ I am looking for a way to determine the number of rows in the table that contain a specific value. For instance, ...

Implementing Angular 4 to fetch information from a JSON file

As a beginner in Angular, my current task involves loading data from a JSON file upon click, which I have successfully achieved so far. However, I am facing an issue where I'm unable to load the first JSON object before clicking, meaning that I want ...

Uncover a one-of-a-kind identifier within the jQuery each() method

Is there a way to create a selector that can accurately refer to the current targeted DOM element (referred to as this) within an iteration of a jQuery each loop? For example, if the selector were #abc, .xyz and the HTML source was: <body> ...

Select dropdown in AngularJS for Date formatting

After retrieving json data from a web API, I found that it contains a series of datetimes. My goal is to select a specific datetime from a dropdown list. While I can populate the list without any issues, the formatting appears to be incorrect and I'm ...

Make sure to update the package.json file at multiple locations following the execution of the "npm i" command

My goal is to automatically detect any newly installed packages based on my package.json file. This way, whenever I run "npm i", the new package will be added not only to the usual "dependencies" section but also to a custom section called "extDependenci ...

How can you ensure a form is properly validated using javascript before utilizing ajax to submit it

I've been working on developing a website and I am in need of an attractive login/registration/forgot password form. My aim was to utilize 'ajax' to enhance the user experience, leading me to immerse myself in a steep learning curve for the ...

While looping through Facebook Graph, the gender information cannot be fetched

Currently, I am utilizing the Facebook Graph API to retrieve gender information from a list of Facebook users. I possess the user's IDs (who are current users of my application). In this case, special permissions are not required to access gender info ...

Creating a stationary div element solely with Javascript, excluding the use of CSS, jQuery, and HTML

I've been searching all day for a solution to this issue without any success. I apologize if I overlooked any relevant posts on the topic. Currently, I am working with Qualtrics and attempting to implement a textbox with scrolling instructions that fo ...

Ways to specify the styles for tr, td, and label elements within a material table

Hey there! Currently, I'm working with material table in react. I came across this page: https://material-table.com/#/docs/features/styling, where it mentions that we can use cellStyle, headerStyle. But what if I want to add more detailed styles to e ...

I tried utilizing the wrapper feature, but unfortunately, the modal did

import React, { PropTypes } from 'react'; import Dialog from 'material-ui/Dialog'; export default class CustomModal extends React.Component { constructor(props){ super(props) } handlePrimaryButton = () => { this.prop ...

Building a Wordpress website with AJAX functionality using only raw Javascript and no reliance on Jquery

So, I have a custom script named related-posts.php, and I want to insert it into posts only when the user scrolls. In addition, I have an enqueued script file in WordPress that loads in the footer, where I have written AJAX code like this: var xmlhttp = ...

The CSS formatting is not being properly applied within the innerHTML

I have a scenario where I am trying to display a Bootstrap card using innerHTML in my TS file, but the styles are not being applied to this content. I suspect that the issue might be because the styles are loaded before the component displays the card, cau ...