Premium support for our pure JavaScript UI components


Post by MauriceLapre »

Hi,

I'm having an issue with characters like á and ñ in the task name. They end up being unknown, question mark symbols:

charactersissue-1.png
charactersissue-1.png (3.67 KiB) Viewed 761 times

The server response via Ajaxhelper.fetch is fine:

charactersissue-2.png
charactersissue-2.png (26.56 KiB) Viewed 761 times

But then after parsing, in the data.parsedJson it's scrambled:

charactersissue-3.png
charactersissue-3.png (26.56 KiB) Viewed 761 times

Part of my code:

AjaxHelper.fetch(fetchUrl, {
                mode : 'no-cors',
                method : 'POST',
                parseJson : true,                
body :JSON.stringify(requestData),
headers : { 'Content-Type': 'application/json', 'Request-Source': 'XMLHTTP', 'Request-Type': 'XMLHTTP'
}
}).then(function(response) { console.log('response'); console.log(response); return iscloud == true ? response : response.text(); // = true }).then(function(data) { console.log('response to text if needed'); console.log(data); console.log(data.parsedJson);

Am I missing an encoding setting or something?

Thank you.


Post by tasnim »

Hi,
Could you please provide raw server response in clear text?

Best regards,
Tasnim


Post by MauriceLapre »

Raw server response:

{
    "2UMWOL": [
        {
            "code": "11661",
            "comments": "",
            "parentwo": "",
            "equipment": "ALG.000",
            "priority": "P2",
            "startdate": "2022-05-02 00:00:00.0",
            "costcode": "",
            "assignedto": "MAURICE.LAPRE",
            "rstatus": "R",
            "eamproject": "",
            "wotype": "BRKD",
            "equipmentdesc": "Gebouwen Algemeen",
            "enddate": "2022-05-06 00:00:00.0",
            "schedenddate": "06-MAY-2022",
            "organization": "SD01",
            "targetdate": "02-MAY-2022",
            "name": "Test ~ñ à á !@#$%^&*()",
            "requestend": "",
            "requeststart": "",
            "department": "*",
            "class": "",
            "supervisor": "",
            "status": "WOP"
        }
    ]
}

Post by mats »

If I run this in our basic sample, it works just fine

AjaxHelper.fetch('../_datasets/launch-saas.json', {
    mode      : 'no-cors',
    method    : 'POST',
    parseJson : true,
    body      : JSON.stringify({ foo : 'bar' }),
    headers   : {
        'Content-Type'   : 'application/json',
        'Request-Source' : 'XMLHTTP',
        'Request-Type'   : 'XMLHTTP'
    }
}).then(function(data) {
    console.log('response to text if needed');
    console.log(data);
    console.log(data.parsedJson);
});

Output in image, so must be something on your server.

Attachments
Screenshot 2022-05-07 at 14.48.43.png
Screenshot 2022-05-07 at 14.48.43.png (273.56 KiB) Viewed 731 times

Post by MauriceLapre »

Thanks for investigating. But how can it be something on my server when my server responds correctly? And only after parsing the response data via the Ajaxhelper.fetch, the weird characters show up?


Post by mats »

What's your server responding, can you please paste headers?

Related discussion: https://stackoverflow.com/questions/55282444/javascript-fetch-characters-with-encoding-issues


Post by MauriceLapre »

It's indeed

Content-Type: application/json;charset=ISO-8859-1

. So, characters seem the same but aren't, I assume.

I have requested to change this to utf-8, assume that should solve the issue.

Thanks for that hint, Mats!


Post by mats »

Glad it's resolved :)


Post Reply