WCF Web Service Result: Unexpected Token Illegal - ParserError (Chrome/IE9/Not Firefox)
I am getting "SyntaxError: Unexpected token ILLEGAL" from Google Chrome and "Unterminated string constant" from IE9 (both are reported as ParserErrors) when I receive the result of an ajax request through jQuery. This function works fine in Firefox.
The result in Chrome from Webkit dev tools is:
"{"LoginResult":{"ErrorMessage":null,"Succeeded":true,"SuccessMessage":null,"AuthToken":"504F4DB7C9C5599AFDE10BBE6B147338042378C5AA2B6F6FE832C29914AD8011161917D496FA037807CCF70D9324B57C56D13C666105DDF7A9A4D3E4D3B20186008D423A31CC4D752DB281A723C726BFADBAA1EDA0F1B878EA9A23DD14A21168CFC5F01122479AA4C95917C477655B005E5094E200839E64F6EAF7D56845D30C08728E8E9BE1F4B503B919A88CF98321F77109D0AFC8DFD347A01BFCEBE728D31F1F1F6AFE2A4DF5675E6D03C29638CEF027DEC52D5"
The result in IE9 from IE dev tools is:
"{\"LoginResult\":{\"ErrorMessage\":null,\"Succeeded\":true,\"SuccessMessage\":null,\"AuthToken\":\"AB0FB8336925444BC679E757A8237BDBE9B379C2BE0CD81502CDAE53F78BCE6896D33A54AD8C436E6C6E61C99C631A7363EFAB260A82256508D4A5D0C5891A3F6C124577F743E802CDF3开发者_如何学JAVAE6E3A182E4614E2670DA010731CCEE115C9DED6C73138F7D97CB8E1E77DE572026D230D1DEE4C481A69C6E22C934CC0D855E3A2E7221CF666C6682E329B82B872751F5F297126BBA545D3027271681C9AA63073E4A018A04AD8A7EEC6E065F0074AF7FE343F190A65E2FCA"
The result in Firefox from Firebug is:
"{\"LoginResult\":{\"ErrorMessage\":null,\"Succeeded\":true,\"SuccessMessage\":null,\"AuthToken\":\"B278D66AD2CCF3CC40DE4AB16D75ED691E1B63F7E93D89E351CF3AA518D4D85D5212753EB26D3CDB22BF70F6369E8CB42B9BDE8079B8B60C42BD3BE3C9FF3670892C8049B64ABB47ED4117FAED8C5F36B35C99241398232B9F5EF4AC8702F2A3984B3FE0E3E5CF5A642C7A2140EFE249EC15755D5971C49EE5F863A0C8EBE10E2973532843656A4C6A89B3E4333F55B7180C2614C92BB28E18611FAE6894DF835AF965E82F762B67B7030559B4CBE6C9DCAD38B1667D347EE44CDED5207ABF5967D947FEE1DAC788F656ACBE395444F4418979A906DA2788C02666BCB1002EE3\"}}"
As you can see, for this particular request, the responseText
of the jquery ajax call seems to be truncated at that point in the authToken for Chrome and IE, although I don't know why as they are all just hex chars.
The function works on the server side, it is just the result once it gets to the client side that is the issue.
I use a common ajax request function, that passes parameters in order to create the request.
These are the important parameters.
- async: true
- method: "GET"
- data: {}
- serviceUrl: "ServiceName.svc/Login?username=user.name&password=dev&rememberMe=false"
The following is my ajax call code:
$.ajax({
async: async,
cache: false, // don't cache results
type: method,
url: Lib.Services.baseUrl + serviceUrl,
contentType: "application/json; charset=utf-8",
data: data,
dataType: "json",
processData: false, // data processing is done by ourselves beforehand
success: function (data, statusText, request) {
if (data !== null && data !== {}) {
if (data.d && data.d.__type) {
data = data.d;
}
else {
var keys = [];
for (key in data) {
if (data.hasOwnProperty(key)) {
keys.push(key);
}
}
if (keys.length !== 1) {
}
else {
// Wrapped message: return first property
$.each(data, function (name, value) {
data = value;
return false;
});
}
}
}
if (data === null) {
window.location = "/login";
}
else {
successHandler(data, statusText, request);
}
},
error: function (request, statusText, error) {
var res = request.responseText;
if (request.status !== 200) {
if (!request.isResolved()) {
if (request.status === 0 && Lib.debug) {
Lib.ShowError("Debug: Check solution is running");
}
else {
Lib.ShowError(request.status + " " + error);
}
}
else {
Lib.ShowError("Request could not be resolved.");
}
}
else {
Lib.ShowError("Unknown error status.");
}
if (typeof (errorHandler) === "function") {
errorHandler();
}
}
});
When I run this call, the "Unknown error status" message is shown.
I have searched and viewed numerous posts about this message, but the issue typically seems to be with the request, rather than the result.
Does anyone have any clues as to what might be causing this? It seems to be happening for all my web service requests (for example, in Chrome, the responseText
of another of my services is just "{"GetStatusDat"
)
The method responses are typical Wrapped WCF responses, with request and response type of Json.
Browsers: Firefox 5.0 | Chrome 12.0.742.112 | IE9 9.0.8112.16421: Update versions 9.0.1
I discovered what the issue was.
I remembered that I had enabled the RadCompressionModule from Telerik in web.config:
<httpModules>
<add name="RadCompression" type="Telerik.Web.UI.RadCompression" />
</httpModules>
This seems to interfere with (i.e. compress) the JSON returns of any web service call in a way that only Firefox can deal with. Strangely, Internet Explorer 6 was fine with it, but I have a feeling that the compression module is disabled for IE6.
If anyone has any ideas for getting the two working together, they would be greatly appreciated.
精彩评论