Search code examples
javascriptajaxobjectuploader

how to change a obj value in the uploader (ajax)?


i still try to change just 1 value on thish Script via js (remotePath), please give me informations :)

Thank you!

$('#uploader_div').ajaxupload(
        {
        url:            'upload.php',
        dropArea:       '#drop_here',
        remotePath:     'user/user1/',  <-- how to change only this value
        ...

like this

            remotePath:     'user/user2/'

Update:

<div id="uploader_div"></div>
<a id="link" href="#" onclick="newvalue();"> Change user2 </a> <!--Change by Click-->
<script>
    var uplobj = {
        url: 'upload.php',
        dropArea: '#drop_here',
        remotePath: 'user/user1/', // Change by Click
        autoStart: true,
        hideUploadButton: true,
        removeOnSuccess: true, 
        maxConnections: 0,
        maxFileSize: '20M',
        allowExt: ['mp3']
    };
    function newvalue() 
    {
        uplobj.remotePath = 'user/user2/'; // Change by Click
        link.style.display = 'none';
    };    
    $('#uploader_div').ajaxupload(uplobj);
</script>

Solution

  • You can change an object anytime before the ajax call if you have a reference to it.

    var obj = {
        url:            'upload.php',
        dropArea:       '#drop_here',
        remotePath:     'user/user1/'
    };
    obj.remotePath = 'user/user2/';
    $('#uploader_div').ajaxupload(obj);
    

    EDIT in response to more code

    I read through the docs you are supposed to pass a standard jquery options object to ajaxupload. Right now you have a mix of jquery options and the data perhaps see the jquery docs for more info on what settings are valid.

    A simple fix might be putting your current data in the data options attribute.

    $('#uploader_div').ajaxupload({data: obj});