birdy
birdy

Reputation: 9636

fetching text response from the server using jquery file upload plugin

My server returns a simple string which I want to alert out and append to a div. So I do the following in jquery file upload

$('#fileupload').fileupload({
    dataType: 'text',
    done: function (data) {
        alert(data)
       $('#result').html(data); 
    }
});

I've also tried this variation

$('#fileupload').fileupload({
    dataType: 'html',
    done: function (e, data) {
        alert(data)
       $('#result').html(data); 

    }
});

however, the alert shows 'Object' and the #result div is not updated with the response. I've seen the response using firebug and he response does infact come from the server and it is simply a string.

Update

after some debugging I found this code to be working fine, but not sure if this is the best way to do this.

$('#fileupload').fileupload({
    dataType: 'text',
    done: function (e, data) {
        console.log("done", data.result);
       $('#result').html(data.result); 

    }
});

Upvotes: 3

Views: 6118

Answers (1)

Ntropy Nameless
Ntropy Nameless

Reputation: 876

If you use FireBug for Firefox, or Chrome, press F12 and place a debugger; statement before the alert statement.
Javascript debugger (any of it) will pause on this line so you can explore the value of the data variable. It seems to be a structure, not just plain text.

Upvotes: 2

Related Questions