Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Dec 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    How to return php values to javascript (for 'AjaxfileUpload')

    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:

    Code:
     $('#buttonUpload').click(function (){
                   
                    $.ajaxFileUpload({
     
                        url:'doajaxfileupload.php',
                        secureuri:false,
                        fileElementId:'fileToUpload',
                        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); }
                            }
                            document.getElementById('buttonUpload').style.color="green";
                            document.getElementById('isfileuploaded').value="green";
                        },
    
                        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.
    Last edited by alex.C; 12-08-2011 at 03:13 PM.

  • #2
    New to the CF scene
    Join Date
    Dec 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Nevermind, I solved it on my own, I just read about json. For people interested:
    Code:
    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
    Code:
    <?php
    
    ...
    ...
    
    ...
    
    echo "{'msg':'".$msg."','error':'".$error."','variable':'".$variable."'}";
    
    ?>


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •