【发布时间】:2013-11-30 02:18:33
【问题描述】:
所以,我试图在使用 Express 构建的服务器中结合跨域服务和基本身份验证。对于我在客户端使用的特定路由,请使用以下 ajax 调用:
$.ajax({
type: "PUT",
accepts: "application/json",
url: aURL,
data: JSON.stringify(toPut),
contentType: "application/json; charset=UTF-8",
dataType: "json",
success: function(data, textStatus, jqXHR) {
alert("Received success: '" + JSON.stringify(data) + "'");
},
error: function (data, textStatus, errorThrown) {
alert("Received error: '" + JSON.stringify(data) + "'\n Status: '" + textStatus + "'\n error thrown = '" + errorThrown + "'");
},
crossDomain: true,
xhrFields: {
withCredentials: true
},
username: myData.username,
password: myData.password
}).done(function() {;}).fail(function() {
alert( "error while putting something" );
}).always(function() {;});
但是,在服务器的控制台中,我并没有真正看到 OPTIONS 请求进入。可能是什么问题?
【问题讨论】:
标签: jquery ajax cors basic-authentication http-request