我在php文件和onUploadComplete中使用以下jquery / ajax代码我想调用位于外部js文件中的函数totalprice()(js文件已经加载)。
现在控制台抛出错误:Uncaught ReferenceError:未定义totalprice
在这种情况下如何定义函数totalprice()?
PHP文件:
<script type="text/javascript">
<?php $timestamp = time();?>
$(function() {
$('#file_upload').uploadifive({
'auto' : true,
'height' : 30,
'width' : 180,
'multi' : false,
'removeCompleted' : true,
'fileSizeLimit' : 6000,
'buttonText' : 'Choose your image',
'formData' : {
'timestamp' : '<?php echo $timestamp;?>',
'token' : '<?php echo md5('unique_salt' . $timestamp);?>'
},
'queueID' : 'queue',
'uploadScript' : '/inc/conf_user_uploader/uploader.php',
'onUploadComplete' : function(file, data) {
console.log(data);
$('.pane').load('/conf_upload_image.php');
$('.label-bodyprintImage').html('Custom image');
$('.price-bodyprintImage').html( $('input:[name=customImagePrice]').val() );
totalprice();
}
});
});
</script>
JS档案:
function totalprice() {
var sum = 0;
sum = Number($('.price-bodyImage').text())
+ Number($('.price-waistbandImage').text())
+ Number($('.price-collarImage').text())
+ Number($('.price-standupcollarImage').text())
+ Number($('.price-leftsleeveImage').text())
+ Number($('.price-leftsleevecuffImage').text())
+ Number($('.price-rightsleeveImage').text())
+ Number($('.price-rightsleevecuffImage').text())
+ Number($('.price-hoodImage').text())
+ Number($('.price-bodyprintImage').text())
+ Number($('.price-leftsleeveprintImage').text())
+ Number($('.price-rightsleeveprintImag').text())
;
$('.price-totalprice').html(sum);
}