Upload script - Javascript variable inside jQuery parameter
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,
精彩评论