开发者

Upload script - Javascript variable inside jQuery parameter

开发者 https://www.devze.com 2023-04-05 23:19 出处:网络
I can\'t tell if I\'m misunderstanding the syntax or if I\'m not understanding the concept.I want to take a javascript variable and concatenate it into a URL parameter inside a jQuery function.The var

I can't tell if I'm misunderstanding the syntax or if I'm not understanding the concept. I want to take a javascript variable and concatenate it into a URL parameter inside a jQuery function. The variable is reassigned by another upload script's jQuery function.

<script type="text/javascript">
var trackid = 12;


jQuery(document).ready(function() { 

    $('#mainftp2').uploadify({
    'uploader'  : 'js/uploadifymultiple/uploadify.swf',
    'script'    : 'js/uploadifymultiple/uploadify.php?<?php echo urlencode("songid=" . $songid . "&userid=" . $userid . "&trackid=);?>'+trackid+'"',
    'multi'         : true,
    'auto'          : true,
    'height'        :   '32', //height of your browse button file
    'width'         :   '250', //width of your browse button file
    'sizeLimit' :   '51200000',  //remove this to set no limit on upload size
    开发者_运维知识库'simUploadLimit' : '3', //remove this to set no limit on simultaneous uploads
    'buttonImg' : 'img/browse.png',
    'cancelImg' : 'img/cancel.png',
        'folder'    : '<?php echo $multiFolder?>', //folder to save uploads to
        onProgress: function() {
          $('#loader2').show();
        },
        onComplete: function(event, queueID, fileObj, response, data) {
          $('#loader2').hide();
          $('#allfiles2').load(location.href+" #allfiles2>*","");
          $('#filesUploaded2').attr('value', ''+response+'');

          //location.reload(); //uncomment this line if youw ant to refresh the whole page instead of just the #allfiles div
        }   
    });

    $('ul li:odd').addClass('odd');

}); 
    </script>


Check the location of your double-quotes, you're missing one inside the PHP fragment, and have an extra one at the end of the URL.

script: 'js/uploadifymultiple/uploadify.php?<?php echo urlencode("songid=" . $songid . "&userid=" . $userid . "&trackid=);?>'+trackid+'"',

First we'll focus on the part we know is wrong:

'uploadify.php?<?php echo urlencode("songid=" . $songid . "&userid=" . $userid . "&trackid=);?>'+trackid+'"',

The question mark is after the .php part. songid and userid seem fine.

'uploadify.php?<?php echo urlencode("&trackid=);?>'+trackid+'"',

Oh crap, where's the closing quote in our call to urlencode?

'uploadify.php?<?php echo urlencode("&trackid=");?>'+trackid+'"',

So now we have a string that's part JavaScript, part PHP, and it's right.

'uploadify.php?etc&trackid=' + trackid + '"',

But URLs don't have trailing quotes, so there must be an extra.

'uploadify.php?etc&trackid=' + trackid,
0

精彩评论

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