1

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
6
  • 1
    what if you alert the whole data returned? is it undefined too? Commented May 13, 2014 at 15:06
  • i think the url is wrong Commented May 13, 2014 at 15:08
  • Use your debuggers (e.g. Chrome tools or whatever). Make the ajax call, look in the Network pane for the response. Is the response code 200? Have have look at the response, has it returned json data? Commented May 13, 2014 at 15:09
  • This may help you: stackoverflow.com/questions/6278694/url-action-parameters Commented May 13, 2014 at 15:12
  • I just did alert(data), got [object] [object] Commented May 13, 2014 at 15:15

1 Answer 1

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

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.