如何使用基本身份验证进行 jquery 多部分表单?
我正在尝试使用 jquery 表单插件 提交具有基本身份验证的多部分文件上传表单。以下是我的代码。但是当我用 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);
I am trying to use jquery form plugin to submit a multipart file upload form with basic authentication. Following is my code. But when I debug with firebug, it seems that the header for auth has never been written to the request.($.base64.encode is another plugin i am using, tested)
Please help me with this and thank you in advance!
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);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论