我正在尝试使用jquery form plugin提交具有基本身份验证的多部分文件上载表单。以下是我的代码。但是当我使用firebug进行调试时,似乎auth的头文件从未写入请求。($。base64.encode是我正在使用的另一个插件,已经过测试) 请帮助我,并提前感谢你!
var formOptions = {
target: '#createAssetForm',
success: showResponse, // post-submit callback
// other available options:
url: URL_BASE+"assets", // override for form's 'action' attribute
type: "POST", // 'get' or 'post', override for form's 'method' attribute
dataType: "json", // 'xml', 'script', or 'json' (expected server response type)
timeout: 3000,
error: function(jqXHR, textStatus, errorThrown){
alert("error " + jqXHR.status);
},
beforeSend: function(xhr) {
xhr.setRequestHeader("Authorization", "Basic " + $.base64.encode(user + ":" + password)); //May need to use "Authorization" instead
xhr.setRequestHeader("Accept", "application/json");
},
};
$('#form').ajaxForm(formOptions);