发送没有标头的ajax请求。 Node.js错误:
{[错误:不支持的内容类型]状态:415,statusCode:415}
但是,如果请求带有标头,则不会对node.js做出反应
我的ajax功能:
function ajax() {
var http = createRequestObject();
if (http) {
var callback, url, method, obj, params='';
var len_args = arguments.length;
if (len_args == 4) {
url = arguments[0];
method = arguments[1];
params = arguments[2];
callback = arguments[3];
if (method == 'post') {
//http.setRequestHeader('Content-Type', 'multiparty/form-data');
//http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
//http.setRequestHeader('Content-Type', 'multiparty/form-data');
}
} else if (len_args == 2) {
url = arguments[0];
method = 'get';
callback = arguments[1];
}
http.open(method, url, true);
http.onreadystatechange = function () {
if (http.readyState == 4) {
callback(http.responseText);
}
}
http.send(params);
}
else {
//document.location = url;
}
}
可能是什么问题?
答案 0 :(得分:0)
而不是http.setRequestHeader('Content-Type', 'multiparty/form-data');
请http.setRequestHeader('Content-Type', 'multipart/form-data');
(我们将multiparty
更改为multipart
)。