Answer the question
In order to leave comments, you need to log in
What encoding to return data in ajax request?
People, I still can’t figure out what encoding and how to correctly return data from the server via ajax.
ajax request:
BX.ajax({
url: '...................',
method: 'POST',
//dataType: 'json',
cache: false,
onsuccess: function(data){
parsed = JSON.parse(data);
// console.log("Fetched saves list: ");
console.log(parsed);
},
onfailure: function(data){
console.log('Failed to load saves list.');
console.log(data);
}
});
require_once($_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/include/prolog_admin_before.php");
require_once($_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/testpartner.testpartnermodule/include.php");
use Bitrix\TestPartner\TestPartnerModule\TestPartnerModuleListTable;
$rsData = TestPartnerModuleListTable::GetList();
$result = array();
while ($row = $rsData->fetch())
{
$listItem = array(
'id' => $row['ID'],
'name' => $row['NAME']
);
array_push($result, $listItem);
}
echo json_encode($result);
Answer the question
In order to leave comments, you need to log in
Since JSON is encoded with Unicode characters , UTF-8 encoding is the best option.
As a practicing developer on 1C-Bitrix, I strongly recommend that you translate projects into UTF-8.
PS You have a namespace
And should be:
Since you are not Bitrix and you do not need to mislead anyone :)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question