XF2.3's XF.ajax behaves differently depending on HTTP method for handling data argument

Xon

Well-known member
Affected version
2.3.5
In XF2.2, XF.ajax supported GET method using $(form).serializeArray() for the data argument. In XF2.3 this fails when using the replacement method XF.Serializer.serializeArray.

Both versions of serializeArray produce the same output format ie;
JSON:
[
{name:'foo', value: 'bar}
]

In XF2.3, XF.ajax use URLSearchParams to encode the arguments for GET which doesn't support serializeArray output format.
JavaScript:
async ajax (method, url, data = {}, successCallback, options = {})
...
if (method.toUpperCase() === 'GET')
{
    url += (url.includes('?') ? '&' : '?') + new URLSearchParams(data).toString()
}
else
{
    if (data instanceof FormData)
    {
        body = data
    }
    else if (Array.isArray(data))
    {
        body = XF.Serializer.serializeFormData(data)
        headers['Content-Type'] = 'application/x-www-form-urlencoded'
    }
    else
    {
        body = JSON.stringify(data)
        headers['Content-Type'] = 'application/json'
    }
}

However using POST http method type works
 
Back
Top Bottom