简体   繁体   English

全局变量不起作用

[英]Global variables are not coming to function

I am using swfupload plugin. 我正在使用swfupload插件。 When I am trying to upload an image I want to pass two parameters but the parameters are not being passed. 当我尝试上传图像时,我想传递两个参数,但未传递参数。

                 var id1='g';
                var opt1='g';
       function getValues()
                {
                    id1 = $("#id").val();
                    opt1=$("#opt").val();
                    return id1.concat(opt1);
                }

             $(document).ready(function(){

             alert(getValues()); // Here coming

            $('#swfupload-control').swfupload({
                upload_url: "upload-file.php?para=getValues()",//Here not coming
                file_post_name: 'uploadfile',
                file_size_limit : "8024",
                file_types : "*.jpg;*.png;*.gif",
                file_types_description : "Image files",
                file_upload_limit : 10,
                flash_url : "js/swfupload/swfupload.swf",
                button_image_url : 'js/swfupload/wdp_buttons_upload_114x29.png',
                button_width : 114,
                button_height : 29,
                button_placeholder : $('#button')[0],
                debug: false
            })
            .bind('fileQueued', function(event, file){
                var listitem='<li id="'+file.id+'" >'+
                    'File: <em>'+file.name+'</em> ('+Math.round(file.size/1024)+' KB)         <span class="progressvalue" ></span>'+
                    '<div class="progressbar" ><div class="progress" ></div></div>'+
                    '<p class="status" >Pending</p>'+
                    '<span class="cancel" >&nbsp;</span>'+
                    '</li>';
                $('#log').append(listitem);
                $('li#'+file.id+' .cancel').bind('click', function(){
                    var swfu = $.swfupload.getInstance('#swfupload-control');
                    swfu.cancelUpload(file.id);
                    $('li#'+file.id).slideUp('fast');
                });
                // start the upload since it's queued
                $(this).swfupload('startUpload');
            })
            .bind('fileQueueError', function(event, file, errorCode, message){
                alert('Size of the file '+file.name+' is greater than limit');
            })
            .bind('fileDialogComplete', function(event, numFilesSelected, numFilesQueued){
                $('#queuestatus').text('Files Selected: '+numFilesSelected+' / Queued Files: '+numFilesQueued);
            })
            .bind('uploadStart', function(event, file){
                $('#log li#'+file.id).find('p.status').text('Uploading...');
                $('#log li#'+file.id).find('span.progressvalue').text('0%');
                $('#log li#'+file.id).find('span.cancel').hide();

            })
            .bind('uploadProgress', function(event, file, bytesLoaded){
                //Show Progress
                var percentage=Math.round((bytesLoaded/file.size)*100);
                $('#log li#'+file.id).find('div.progress').css('width', percentage+'%');
                $('#log li#'+file.id).find('span.progressvalue').text(percentage+'%');
            })
            .bind('uploadSuccess', function(event, file, serverData){
                var item=$('#log li#'+file.id);
                item.find('div.progress').css('width', '100%');
                item.find('span.progressvalue').text('100%');
                var pathtofile='<a href="uploads/'+file.name+'" target="_blank" >view &raquo;</a>';
                item.addClass('success').find('p.status').html('Done!!! | '+pathtofile);
            })
            .bind('uploadComplete', function(event, file){
                // upload has completed, try the next one in the queue

                $(this).swfupload('startUpload');

            })
        });
 });
    </script>

You have your function call in a string. 您在字符串中有函数调用。 You need to break the string and concatenate the function's results onto your string. 您需要断开字符串并将函数的结果连接到字符串上。

upload_url: "upload-file.php?para=getValues()"

becomes: 变成:

upload_url: "upload-file.php?para=" + getValues()

The line with the following code does not call the function getValues() because it is just a string. 包含以下代码的行不会调用函数getValues(),因为它只是一个字符串。

upload_url: "upload-file.php?para=getValues()",

I'm assuming you want to call the function, not put "getValues()" in the url, correct? 我假设您要调用该函数,而不要在网址中放入“ getValues()”,对吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM