Hello and good evening,
I writing a simple PHP ecommerce website and I've stumbled upon a problem while doing the administration portion of it. I'm currently trying to do an AJAX request to fill some fields on a bootstrap modal and for that I go get the data from a database:
function editProductResponse($productId)
{
require 'app/database/Database.php';
require 'app/models/Product.php';
require 'app/models/ProductImage.php';
$product = new Product();
$object = $product->getProduct($productId);
$data = $object[0];
$array = [
"id" => $data->id,
"name" => $data->name,
//"description" => $data->description,
"price" => $data->price,
"stock" => $data->stock,
"sold" => $data->sold,
"added" => $data->added,
"type" => $data->type,
"subtype" => $data->subtype,
"discount" => $data->discount
];
echo print_r($data);
echo json_encode($array);
}
That's my ajax.php
function that gets that actual data and this works fine (bear in mind the commented part of the array is not a mistake, I'll explain that bellow; also i'm doing an array for debug purposes):
stdClass Object
(
[id] => 1
[name] => MSI Nightblade MI2-027XES Gaming
[description] => Forjado com a paix�o pelo jogo, o MSI Nightblade MI2 foi feito para aqueles que anseiam por uma experi�ncia de jogo imersiva. Com armazenamento em abund�ncia, refrigera��o eficiente e gr�ficos de alta qualidade, esta pequena m�quina gaming est� pronta para desbloquear a sua pr�xima aventura gaming.
[price] => 799
[stock] => 147
[sold] => 32
[added] => 2010-11-22
[type] => COMPUTER
[subtype] => DESKTOP
[discount] => 10
)
1{"id":1,"name":"MSI Nightblade MI2-027XES Gaming","price":799,"stock":147,"sold":32,"added":"2010-11-22","type":"COMPUTER","subtype":"DESKTOP","0":"discount => 10"}
This is my response in the browser log. Everything appears to be working fine and it is. So my problem is when I actually uncomment the description part from the array. If I do so, I get this:
stdClass Object
(
[id] => 1
[name] => MSI Nightblade MI2-027XES Gaming
[description] => Forjado com a paix�o pelo jogo, o MSI Nightblade MI2 foi feito para aqueles que anseiam por uma experi�ncia de jogo imersiva. Com armazenamento em abund�ncia, refrigera��o eficiente e gr�ficos de alta qualidade, esta pequena m�quina gaming est� pronta para desbloquear a sua pr�xima aventura gaming.
[price] => 799
[stock] => 147
[sold] => 32
[added] => 2010-11-22
[type] => COMPUTER
[subtype] => DESKTOP
[discount] => 10
)
1
I left the echo print_r
to avoid any confusion on both results.
After I got this response it made me wonder if there's any sort of limit to JSON or if there's some sort of problem with the TEXT
SQL data type as the description
field is of this type.
As requested, this is the debug response of the actual array:
Array
(
[id] => 1
[name] => MSI Nightblade MI2-027XES Gaming
[description] => Forjado com a paix�o pelo jogo, o MSI Nightblade MI2 foi feito para aqueles que anseiam por uma experi�ncia de jogo imersiva. Com armazenamento em abund�ncia, refrigera��o eficiente e gr�ficos de alta qualidade, esta pequena m�quina gaming est� pronta para desbloquear a sua pr�xima aventura gaming.
[price] => 799
[stock] => 147
[sold] => 32
[added] => 2010-11-22
[type] => COMPUTER
[subtype] => DESKTOP
[discount] => 10
)
1