View Full Version : How to return php values to javascript (for 'AjaxfileUpload')

12-08-2011, 04:10 PM
Hi there,

I am trying to build an interface to upload files and change some of the form (hidden) values depending on the file uploaded, here is where I got so far:

$('#buttonUpload').click(function (){


dataType: 'txt',

success: function (data, status){

alert("File is uploaded,");
if(typeof(data.error) != 'undefined'){

if(data.error !=''){ alert(data.error); }
else{ alert(data.msg); }

error: function (data, status, e){ alert(e); }

return false;

My problem is that I want doajaxfileupload.php to return a variable to javascript/change some html form value. The code works as it is for the file upload, I just need to add something for the output, any suggestion?

Edit: I just noticed that some previous part of the code is still there: the part that changes the color of the button depending if the file is uploaded or not. Now I want those values to change depending on what file is uploaded.

12-08-2011, 07:34 PM
Nevermind, I solved it on my own, I just read about json. For people interested:

dataType ='json'; // I thought it was the file type, it s actually the datatype for the output from the php function

in the php file




echo "{'msg':'".$msg."','error':'".$error."','variable':'".$variable."'}";