I am returning a simple data to ajax call. But I trying show that returned in alert is showing undefined
. How can I get return JSON data?
return Json(new { message = "success", url = Url.Action("Index", "Image") },
JsonRequestBehavior.AllowGet);
view
$(document).ready(function() {
$('#fileupload').fileupload({
dataType: 'json',
url: '/Admin/Image/UploadFiles',
autoUpload: true,
done: function (e, data) {
alert(data.message); //showing undefined
if (data.message== 'success') {
alert(data.message);
window.location = "www.google.com";
}
},
fail: function(e, data) {
console.write(data.errorThrown);
}
})
asked May 13, 2014 at 15:04
1 Answer 1
Do you want the complete or success property? You are confusing the xhr object's .done()
with ajax setup property complete:
or success:
I think.
Done's second parameter is a status, not the data.
Try this instead
$(document).ready(function() {
$('#fileupload').fileupload({
dataType: 'json',
url: '/Admin/Image/UploadFiles',
autoUpload: true,
success: function (data, status, xhr) {
alert(data.message);
if (data.message== 'success') {
alert(data.message);
window.location = "www.google.com";
}
}
})
answered May 13, 2014 at 15:12
Sign up to request clarification or add additional context in comments.
Comments
Explore related questions
See similar questions with these tags.
default
alert(data)
, got[object] [object]