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)开发者_JS百科;
?>
but its not sending it back i dnt think!!! i tried using firebug, but it dnt show that its posting, to upload.php!!
I don't see that you're sending any data in your code. Take a look to the official documentation especially to data
parameter.
I suspect you are looking for response.pic
and not pic.response
.
You are also failing to specify: header('Content-type: application/json');
精彩评论