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.