简体   繁体   English

用jQuery返回JSON中的数据?

[英]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文件:

<?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!! 我尝试使用firebug,但它显示其发布,上传.php !!

I suspect you are looking for response.pic and not pic.response . 我怀疑您正在寻找response.pic而不是pic.response

You are also failing to specify: header('Content-type: application/json'); 您还没有指定: 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. 请查看官方文档,特别是data参数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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