1

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>

1 Answer 1

0

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,
1
  • I'm having a hard time debugging this. Any chance you could write out what you mean? Commented Sep 19, 2011 at 2:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.