0

Here I have a problem for get and use the properties of an object, I don't understand why I'm stuck on the last few days ... I made a screenshot which may have see the list of properties and methods of the object.

In this case I would go to the "result" property. Problem: When I do "console.log (objet.result)", it returns me "undefined".

It's indeed a XHR object. The script upload files, it uses mainly this plugin : https://github.com/blueimp/jQuery-File-Upload/wiki/API

and here below the code of the script (look around the line "if(progress == 100)") :

$(function(){

var ul = $('#upload ul');

$('#drop a').click(function(){
    // Simulate a click on the file input button
    // to show the file browser dialog
    $(this).parent().find('input').click();
});

// Initialize the jQuery File Upload plugin
$('#upload').fileupload({

    // This element will accept file drag/drop uploading
    dropZone: $('#drop'),

    // This function is called when a file is added to the queue;
    // either via the browse button, or via drag/drop:
    add: function (e, data) {

        var tpl = $('<li class="working"><input type="text" value="0" data-width="48" data-height="48"'+
            ' data-fgColor="#0788a5" data-readOnly="1" data-bgColor="#3e4043" /><p></p><span></span></li>');

        // Append the file name and file size
        tpl.find('p').text(data.files[0].name)
                     .append('<i>' + formatFileSize(data.files[0].size) + '</i>');

        // Add the HTML to the UL element
        data.context = tpl.appendTo(ul);

        // Initialize the knob plugin
        tpl.find('input').knob();

        // Listen for clicks on the cancel icon
        tpl.find('span').click(function(){

            if(tpl.hasClass('working')){
                jqXHR.abort();
            }

            tpl.fadeOut(function(){
                tpl.remove();
            });

        });

        // Automatically upload the file once it is added to the queue
        var jqXHR = data.submit();
    },

    progress: function(e, data){

        // Calculate the completion percentage of the upload
        var progress = parseInt(data.loaded / data.total * 100, 10);

        // Update the hidden input field and trigger a change
        // so that the jQuery knob plugin knows to update the dial
        data.context.find('input').val(progress).change();

        if(progress == 100){
            data.context.removeClass('working');

            //THE VALUE THAT I WANNA GET IS A PROPERTY OF THE DATA OBJECT 
        }
    },

    fail:function(e, data){
        // Something has gone wrong!
        data.context.addClass('error');
    }

});

// Prevent the default action when a file is dropped on the window
$(document).on('drop dragover', function (e) {
    e.preventDefault();
});

});

Please anybody can help me ??

Thankz by advance for your help and good week !

moDevsome
  • 189
  • 2
  • 16

2 Answers2

0

I think this is an issue of response. Javascript unable to evaluate the response(its consider as a string).

first solution->

var obj = eval('{' + res + '}');

second solution->

We can Parse result into json using var response = jQuery.parseJSON(res);

and then access response.result

0

Finally, I've solved my problem.

I did not use the good call back reference to get my data. I put my nose deep in the plugin documentation and I've found an another method than "progress". I must use the "done" callback method if I want to get the "result" value.

However I want to thank you for your help.

Have a nice coding day !!

Mickael

moDevsome
  • 189
  • 2
  • 16