1

This is the JSON i'm getting:

{"status":"failure","msg":{"name":["can't be blank"],"email":["can't be blank","is invalid"]}}

This is the javascript i'm using:

$("#sign_in_form").submit(function() {
  var success_function = function(data) {
    if(data.status == 'failure') {
      $("#error_msg").html(data.msg.name)
    }
  };

  $.post($(this).attr("action"), $(this).serialize(), success_function, "json");
});

The error I'm getting from Firebug is:

uncaught exception: [Exception... "Could not convert JavaScript argument arg 0 [nsIDOMDocumentFragment.appendChild]" nsresult: "0x80570009 (NS_ERROR_XPC_BAD_CONVERT_JS)" location: "JS frame :: http://localhost:3000/assets/jquery.js?body=1 :: <TOP_LEVEL> :: line 6182" data: no]

Everything works fine. My javascript can access the data.status value but using data.msg.name produces the uncaught exception.

2 Answers 2

0

try

data.msg.name[0]

Hope that helps

4
  • I think it might be data.msg.name[0]. Commented Sep 24, 2011 at 23:01
  • It is in fact data.msg.name[0]. The ones above are not correct. Commented Sep 24, 2011 at 23:06
  • @Elliot Nelson tnx for correcting me i was just testing the same thing
    – Rafay
    Commented Sep 24, 2011 at 23:06
  • @EverTheLearner updated the answer, since Elliot answered it too in the comment
    – Rafay
    Commented Sep 24, 2011 at 23:08
0

it should be

$("#error_msg").html(data.msg.name[0] || '');

Your Answer

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.