我使用 AJAX 帖子从服务器端获取数据,我想在我的网页上显示它。
这就是我得到的:
{text: active user
active user213123
idle user234234234
loggedout userafdadf
},
我希望它在text:
. 这是我所做的:(message
是整个json)
AjaxPost: function (dataAttr, view) {
var that = this;
$.ajax({
type: "POST",
url: this.url + " /user",
datatype: "application/json",
contentType: " text/plain",
data: dataAttr,
success: function (data) {},
error: function (error) {},
statusCode: {
400: function (error) {
that.processResponse(error, view);
},
200: function (data) {
that.processResponse(data, view);
}
}
});
},
processResponse: function (messageObj, view) {
if (_.isUndefined(messageObj) || _.isUndefined(view)) {
return "error";
}
switch (messageObj.status) {
case 400:
var objResponse = $.parseJSON(messageObj.responseText);
this.processMessage(false, objResponse, view);
break;
default:
this.processMessage(true, messageObj, view);
break;
}
},
processMessage: function (isSuccess, message, view) {
if (_.isUndefined(isSuccess) || _.isUndefined(message) || _.isUndefined(view)) return "error";
else {
var outputString = "";
var messageResponse = [];
messageResponse = message.split(":");
if (isSuccess) {
output = messageResponse.split(":");
}
view.showMessage(String);
}
但我收到此错误:
未捕获的类型错误:
Object #<Object> has no method 'split'