jQWidgets Forums

jQuery UI Widgets Forums General Discussions fileUploader response is undefined

Tagged: 

This topic contains 1 reply, has 2 voices, and was last updated by  Hristo 4 years, 3 months ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
  • fileUploader response is undefined #114134

    NormB
    Participant

    I need help understanding how to get response back from the PHP call when using jqxfileupload.

    I have a hidden div on my web page because I want to trigger the upload from a different button.
    The widget is instantiated at page creation as follows:

    
    	$('#jqxFileUpload').jqxFileUpload({
    		multipleFilesUpload: false,
    		fileInputName: 'UploadNew'
    	});
    	$('#jqxFileUpload').on('select', function(event) {
    		$(this).jqxFileUpload('uploadFile', 0);
    	});
    	$('#jqxFileUpload').on('uploadEnd', function(event) {
    		var fileName = event.args.file;
    		try {
    			if(!event.args.response) {
    				jqAlert('No response received from DancesData.php');
    			} else {
    				var response = JSON.parse(event.args.response);
    				if(response.Message) {
    					jqAlert(response.Message);
    				} else { jqAlert(response); }
    				if(response && response.Result==='OK') {
    
    				}						
    			}
    		}
    		catch(err) { jqAlert('ERROR:<br>'+err.message+'<br>Ajax response:<br>'+event.args.response); }
    	});

    At this stage you will notice that there is no url set. Also notice that the “on select” method is used to trigger the upload itself.

    Then, there is a an “on click” action for the button that will trigger the upload (among other things), which sets the url and calls the “browse”: Snippet from that function as follows

    	var url = '/DancingMaster/DancesData.php?action=AddPDF&DanceID='+currentDanceData.ID;
    	$('#jqxFileUpload').jqxFileUpload({ uploadUrl: url});
    	$('#jqxFileUpload').jqxFileUpload('browse');

    The DancesData.php code is, as yet, very simple because I am trying to test how to get the response back to the “uploadEnd” function.

    	case 'AddPDF':
    	$dance = $db->where('ID',$danceid)->getOne('dances'); // This is just a call to extract data from my database
    	$ajaxResult['Message'] = "We got here";
    	return json_encode($ajaxResult['Message']);

    The php action is being called as expected and I can confirm that the contents of $_FILES are as expected, so I should be able to upload the file in the usual way. But I also need to return some information back to the javascript (jquery).
    I have tried returning simple text strings, and arrays, both json encoded and raw, but every time when it returns to the “uploadEnd” function event.args.response is undefined.

    What am I doing wrong? – obviously I am misunderstanding how this works

    Thanks

    fileUploader response is undefined #114145

    Hristo
    Participant

    Hello NormB,

    Could you clarify it – why you need to set the URL on the end?
    I would like to suggest you look at this tutorial below you maybe know it but it could be useful:
    https://www.jqwidgets.com/jquery-widgets-documentation/documentation/phpintegration/jquery-fileUpload-with-php.htm?search=
    Also, you could try to use the echo command instead of the return option.

    Best Regards,
    Hristo Hristov

    jQWidgets team
    https://www.jqwidgets.com

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.