当前位置: 动力学知识库 > 问答 > 编程问答 >

php - How to call an external javascript function on ajax success

问题描述:

I am using the following jquery/ajax code in a php file and onUploadComplete I'd like to call the function totalprice() which is located in an external js file (the js file is already loaded).

Right now the console throws the error: Uncaught ReferenceError: totalprice is not defined

How do I define the function totalprice() in this case?

PHP file:

<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 file:

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);

}

分享给朋友:
您可能感兴趣的文章:
随机阅读: