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开发者_JAVA技巧 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);
精彩评论