When using JSON stringify, double quotes are automatically added around any float type data

When passing a float data from my controller to a JavaScript function using JSON, I encountered an issue with quotes appearing around the figure in the output. Here is the JS function:

function fetchbal(){
$.ajax({
    url: "/count/ew",
    dataType: "json"
}).success(function(data){
    $('#bal').html(JSON.stringify(data.sum));
});
}

I verified that the value returned by the controller does not include quotes, so the problem seems to be linked to the JSON stringify method.

To double-check, here is the Symfony controller code:

$repo = $em->getRepository('SystemBundle:Admin');
$user = $repo->findOneBy(array('id'=>$session->get('id')));
$sum = $user->getWallet();
return new JsonResponse(array('sum'=>$sum));

In this code snippet, $sum retrieves a floating point value from the database using Doctrine.

I attempted to apply a solution found on this post, but it caused the value to no longer display on the page.

I am seeking suggestions on how to prevent quotes from surrounding the fetched value. Please provide further clarification if needed.

Answer №1

When using Json stringify, it automatically adds quotes to serialize data for server communication.

If you're using jQuery, there's no need to manually parse the JSON response as jQuery will handle it for you.

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

Ways to retrieve Payload following the Request url access

Currently utilizing Selenium with Python to conduct website testing, I successfully accessed the Request link and now aim to access the Payload. Below is an image displaying the process: view image description here driver = webdriver.Chrome(options=option) ...

JavaScript's addition function is not functioning properly

Does anyone know how to calculate the sum of these variables? var totalPrice = document.values.T1.value; var pounds = document.values.T2.value; var serviceFee = 5.00 var counter1 = 0; var counter2 = 0; var processing = 0; var shippingCost = 0; var ...

Clear Input Field upon Selection in JQuery Autocomplete

I've been experimenting with the Azure Maps API to add autosuggestions for addresses in an input field. https://github.com/Azure-Samples/AzureMapsCodeSamples/blob/master/AzureMapsCodeSamples/REST%20Services/Fill%20Address%20Form%20with%20Autosuggest. ...

What is the best way to navigate to a specific ID on the homepage using a navigation button on another page?

When a navigation button is clicked on any page other than the home page, I want the home page to load first and then scroll to the corresponding id mentioned in the navlink. Below is the code snippet: <Col sm={5}> <Nav className=& ...

Integrate a scrollbar seamlessly while maintaining the website's responsiveness

I encountered an issue where I couldn't add a scrollbar while maintaining a responsive page layout. In order to include a scrollbar in my datatables, I found the code snippet: "scrollY": "200px" However, this code sets the table size to 200 pixels r ...

res.send() triggers an error of TypeError: Attempting to convert circular structure to JSON

I've encountered an error message that has been discussed before, but none of the proposed solutions seem to work for my situation. My current project involves building a backend express server to manage API requests for a React application. I have c ...

Issue: "Autoloader expected class... typo error" message is showing despite no typo in Symfony 4 class inheritance

In my project, I have a file named "Ajuste.php" that belongs to the class: <? // src/App/Entity/Ajuste.php namespace App\Entity; use Doctrine\ORM\Mapping as ORM; use App\SuperClass\Documento as Documento; use Doctrine\Co ...

Getting POST data in Next.js is a common task that requires understanding of how the

I am currently working on a form validation project using the App Router within Next.js. // app/register/page.tsx export default function Register(context: any) { console.log("Register page", context.params, context.searchParams); return ...

Converting JSON to a StringList in Delphi XE5

In my Delphi Xe5 project, I have a component that communicates with a server using IDTCPClient (sockets) to fetch JSON data. The connection code is working fine and the JSON responses are being retrieved successfully. However, I'm facing difficulties ...

Explanation on extracting data from json schema: encountered an error - TypeError: string indices must be integers

In my case, I have acquired a json response from an API structured like this: { "meta": { "code": 200 }, "data": { "username": "luxury_mpan", "bio": "Recruitment Agents ...

"Encountered an OperationalError while trying to insert JSON data into sqlite database: Error message stating that the token "{"" is

In my code, I have implemented something similar to this: import sqlite3 ... sqlString=company['name']+","+simplejson.dumps(info) cur.execute("INSERT INTO companyInfo VALUES("+sqlString+")") However, when running it, I encountered the following ...

`Is it challenging to convert JSON into HTML, leading to undefined results?`

I am currently attempting to extract YAHOO data by utilizing getJSON and YQL. Although the connection is successful, I can retrieve the data and log it in the console. However, I am facing difficulties when trying to display this data on the JSP page I am ...

The jqGrid displaying data with datatype set to "jsonstring" is only showing the first page

When my JqGrid receives data from the server in JSON format, I use the following parameters: _self.GridParams = { rows: 7, page: 1, sidx: '', sord: '' } Once the data is retrieved, it is stored in the variable 'data': Objec ...

"Implementing a full page refresh when interacting with a map using

Here is an example of how I display a map on the entire page: <div id="map_canvas"> </div> UPDATE 2: I have successfully displayed a menu on the map, but there is a problem. When I click on the button, the menu appears briefly and then disapp ...

Instructions for subtracting the value of a cell in column 22 from a cell in column 24 within the same row when a change trigger occurs utilizing Google Apps Script

I need help modifying the script below to only subtract the row on which the change is made, instead of subtracting all rows in the sheet when the on-change trigger executes. var sourceSpreadsheetID = '1r4e4BNKwsmdC2Ry93Mq-N49zj3DAZVpHG21TgTe0FWY&a ...

Using JSON to pass a dynamic array to Morris Chart

My task involves creating a graph using Morris Charts with a dynamic rectangular array. The array consists of a variable number of columns and looks like this: To achieve this, I attempted to pass the data to Morris Charts using JSON. Below is a snippet o ...

Guide to dynamically implementing pagination through AJAX calls

In this javascript code snippet, I have a class named PurchaseHistory. var baseUrl = null; var parameters = null; var currentPageNumber = null; var TotalPages = null; var PageSize = null; $(document).ready(function () { baseUrl = "http://localhost/AP ...

Generating various fields within a single row

I am in the process of creating a dynamic form that should generate two new fields in the same line when the user clicks on the plus icon. Currently, the code I have only creates a single field. I attempted to duplicate the code within the function, but i ...

How can I automatically submit a form upon page load with AJAX and receive the result in HTML format?

Attempting to automatically submit a form when the page loads using ajax and then retrieve the HTML (consisting of multiple divs that will be echoed on the AJAX URL) back to my AJAX page. Firstly, the code successfully auto submits the form but fails to t ...

Is it possible for an image to be displayed in another div or table column when I hover my mouse over it?

I am looking to create an image gallery with thumbnails on the left side. When I hover over a thumbnail, I want the full image to be displayed in another section on the page. Can anyone provide me with the correct code or suggest a plugin to achieve this f ...