Why am I getting “undefined” passed to the db? jquery php plupload

故事扮演 提交于 2020-02-02 14:44:18

问题


I am NOT having trouble passing something into my database, so the "may have already been answered" alert above and the associated link do not answer my question (Thanks for trying to help anyway). My problem is with the jquery variable.

Why is it when I pass $('input[name="ageLimit"]:checked', '#myForm').val() to the alert the variable pulls the correct information, but when I pass it to the url in the plupload function it does not and I end up with undefined in my database. Why might this be happening? permissions? jquery conflict?

<script type="text/javascript">
// Convert divs to queue widgets when the DOM is ready
$(document).ready(function(){ 
   $('#myForm input').on('click', function() {
   alert($('input[name="ageLimit"]:checked', '#myForm').val()); 
   });

});

$(function() {
$("#uploader").plupload({
    // General settings
    runtimes : 'flash,html5,browserplus,silverlight,gears,html4',       
    url : 'upload.php?aud=' + $('input[name="ageLimit"]:checked', '#myForm').val(),
    max_file_size : '1000mb',
    max_file_count: 20, // user can add no more then 20 files at a time
    chunk_size : '1mb',
    rename: true,
    multiple_queues : true,
     //multipart_params : {
          //  aud : $('input[name="ageLimit"]').val()
    //},

    // Resize images on clientside if we can
    //resize : {width : 320, height : 240, quality : 90},

    // Rename files by clicking on their titles
    rename: true,

    // Sort files
    sortable: true,

    // Specify what files to browse for
    filters : [
        {title : "Image files", extensions : "jpg,gif,png"},
        {title : "Zip files", extensions : "zip,avi"}
    ],

    // Flash settings
    flash_swf_url : 'plupload/js/plupload.flash.swf',

    // Silverlight settings
    silverlight_xap_url : 'plupload/js/plupload.silverlight.xap'
});

// Client side form validation
$('form').submit(function(e) {
    var uploader = $('#uploader').plupload('getUploader');

    // Files in queue upload them first
    if (uploader.files.length > 0) {
        // When all files are uploaded submit form
        uploader.bind('StateChanged', function() {
            if (uploader.files.length === (uploader.total.uploaded + uploader.total.failed)) {
                $('form')[0].submit();
            }
        });

         //uploader.bind('BeforeUpload', function(up) {
             // up.settings.multipart_params.aud = $('input[name="ageLimit"]').val();
       // });    
        uploader.start();
    } else
        alert('You must at least upload one file.');

    return false;
});


});
</script>

here is the php code

//check for audience
    $aud = (!empty($_GET['aud'])) ? trim($_GET['aud']): "";

回答1:


I guess that is because no radio button is checked yet when the url option is evaluated in the init of the uploader.

instead of

url : 'upload.php?aud=' + $('input[name="ageLimit"]:checked', '#myForm').val(),

have

url : 'upload.php',

then add, after the plupload call and before the $('form').submit( call :

var uploader = $('#uploader').plupload('getUploader');

uploader.bind('BeforeUpload',function(upldr,file){
    upldr.settings.url = 'upload.php?aud=' + $('input[name="ageLimit"]:checked', '#myForm').val();
    // here some runtimes might need a upldr.refresh(); (Though I'm not sure, I guess I remember Flash would.)
    }
);

Hope this will help



来源:https://stackoverflow.com/questions/20077744/why-am-i-getting-undefined-passed-to-the-db-jquery-php-plupload

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!