为什么我会得到“未定义"的信息?传递给数据库? jQuery的PHP plupload [英] Why am I getting "undefined" passed to the db? jquery php plupload

查看:155
本文介绍了为什么我会得到“未定义"的信息?传递给数据库? jQuery的PHP plupload的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在将某些内容传递到数据库时没有遇到问题,因此上面的可能已经被回答"警报和关联的链接无法回答我的问题(仍然感谢您的帮助).我的问题是与jquery变量.

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.

为什么当我将$('input[name="ageLimit"]:checked', '#myForm').val()传递给警报时,变量会提取正确的信息,但是当我将其传递给plupload函数中的url时却没有,最终我的数据库中会出现undefined.为什么会发生这种情况?权限? jQuery冲突?

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>

这是php代码

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

推荐答案

我想这是因为在上载程序的初始化中评估url选项时,尚未选中任何单选按钮.

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

代替

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

拥有

url : 'upload.php',

然后在plupload调用之后和$('form').submit(调用之前添加:

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.)
    }
);

希望这会有所帮助

这篇关于为什么我会得到“未定义"的信息?传递给数据库? jQuery的PHP plupload的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆