我正在使用jquery Ajax将数据发送到客户端并从客户端获得回复。 我使用Play Framework作为后端。
AJAX:
$.ajax({
type: "GET",
url: '/authenticate',
data: {'type':type, 'redirectURL':getRedirectURL},
contentType: "application/json; charset=UTF-8",
dataType: 'json'
}).success(function( msg, txtStatus, jqXHR) {
console.log("asdasd5= "+msg);
console.log("asdasd5= "+msg.authUrl);
console.log("asdasd5= "+jqXHR.authUrl);
window.location = msg;
});
服务器数据创建:
response.setContentTypeIfNotSet("text/plain; charset=UTF-8");
Logger.info("response content type ="+response.contentType);
renderJSON("{\"authUrl\": " + authUrl +"}");
服务器正在发送类似“www.mywebsite.com/yoohoo/auth/1231”的内容
但Ajax收到的回复是�����������������{"authUrl": www.mywebsite.com/yoohoo/auth/1231}
由于这些奇怪的字符,jQuery无法解析收到的JSON响应。 请帮助。
由于
答案 0 :(得分:0)
我注意到您发送回(服务器端)MIME类型“text / plain”。也许切换到“application / json”。此外,您可以获取返回字符串并从字符串中删除任何垃圾,然后在客户端解析JSON。如果您在服务器端再次更改某些内容并意外引入新的/不同的“垃圾”,这将有助于消毒。