简体   繁体   中英

How to set a specific json response object as a js var - Cloudinary

I am using Cloudinary to host my profile images that are set by users.

I'm mostly using PHP for my web application -> Here are the instructions as provided by Cloudinary http://cloudinary.com/documentation/php_image_upload#overview

The problem that I encounter is that I want to display the image directly after upload by parsing the newly created URL for the image that is returned by JSON.

When I do the console.log as provided by Cloudinary:

    $(document).ready(function() {
        $('.cloudinary-fileupload').bind('cloudinarydone', function(e, data) {
           console.log(data);
           return true;
        });
    });

This is the console.log response that I receive

Can anyone please help me with a javascript or JQuery function that I can use in order to display the updated image with in my image tag.

You need read the tree...

jqXHR.responseJSON.url

In this case, use

data.result.url

See example of http://cloudinary.com/documentation/php_image_upload#preview_thumbnail_progress_indication_multiple_images

Can you update the src of your image tag based on the json returned?

Something like this in the callback function:

var imgDiv = document.getElementById("profile");
imgDiv.src = data.jqXHR.responseJSON.url;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM