开发者

How to do jquery multipart form with basic auth?

开发者 https://www.devze.com 2023-02-19 15:27 出处:网络
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开发者

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); 
0

精彩评论

暂无评论...
验证码 换一张
取 消