简体   繁体   中英

returning data in json with jquery?

var thumb = $('img#thumb');

    new AjaxUpload('imageUpload', {
        action: 'upload.php',
        name: 'image',
                autoSubmit:'json',
        onSubmit: function(file, extension) {
            $('div.preview').addClass('loading');

        },
        onComplete: function(file, response) {
            thumb.load(function(){
                $('div.preview').removeClass('loading');
                thumb.unbind();
            });
            thumb.attr('src',pic.response);
        }
    });

php file:

<?php
$arr = array ('pic'=>'img/img.jpg');

echo json_encode($arr);
?>

but its not sending it back i dnt think!!! i tried using firebug, but it dnt show that its posting, to upload.php!!

I suspect you are looking for response.pic and not pic.response .

You are also failing to specify: header('Content-type: application/json');

I don't see that you're sending any data in your code. Take a look to the official documentation especially to data parameter.

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