I'm trying to call a rest service from jQuery using the code below
$.ajax({
type: verb,
url: url,
headers: header,
crossDomain: true,
xhrFields: {
withCredentials: true
},
contentType: 'application/json; charset=utf-8',
data: JSON.stringify(data),
dataType: 'text',
accept: 'application/json charset=utf-8'
}).done(function (ResultData) {
//do something
}).error(function (jqXHR, textStatus, errorThrown) {
//do something
});
It works perfectly all the time, but when I passed an Arabic character in the header like this:
header["sFilter"]="عربي"
The following error raised:
DOMException: Failed to execute 'setRequestHeader' on 'XMLHttpRequest': 'عربي' is not a valid HTTP header field value.
I tried to add a beforeSend function to set "Content-Type" but nothing changed
beforeSend: function(XMLHttpRequest){
XMLHttpRequest.setRequestHeader("Content-Type", "text/plain;charset=UTF-8");
},
Is there is a way to solve this issue without encoding the text in the client side and decoding it in the server side, as I don't have access to the server side code?