Seven price
asked on
get json value
On error I am returning json results.
I tried json.parse
var text = '{"Message":"The request is invalid.","ModelState":{"model.Email":["The Email field is required."],"model.Password":["The Password field is required."]}}';
var mytext = {"Message":"The request is invalid.","ModelState":{"":["Passwords must have at least one non letter or digit character. Passwords must have at least one lowercase ('a'-'z'). Passwords must have at least one uppercase ('A'-'Z')."]}}
function (error, status) {
I tried json.parse
I noticed in your string, the missing element name.
"ModelState":{""
I assigned "Warning" as name.
"ModelState":{""
I assigned "Warning" as name.
ASKER
ok I know it is valid I am trying to return the value in a alert box.
What is 'function (error, status) {'
You haven't really given us a lot to go on, or indicated where you have a problem.
My guess here is that you are trying to make an AJAX request and expecting the error handler to notice when your username or password aren't valid.
If that's the case, the jQuery request will only receive the JSON data back in the success handler, not the error handler. The error handler only fires if the AJAX request failed.
You haven't really given us a lot to go on, or indicated where you have a problem.
My guess here is that you are trying to make an AJAX request and expecting the error handler to notice when your username or password aren't valid.
If that's the case, the jQuery request will only receive the JSON data back in the success handler, not the error handler. The error handler only fires if the AJAX request failed.
ASKER
Yes I know that, I set up a demo on jfiddler. being lazy today. ok
OK - In that case, do you want to give us some clue as to what your problem is, or at least what you're trying to do?
You've given us exactly 2 variable definitions and 1 function declaration. No errors, no questions, no idea as to what you need. Work with us and we can help you.
You've given us exactly 2 variable definitions and 1 function declaration. No errors, no questions, no idea as to what you need. Work with us and we can help you.
ASKER
http://jsfiddle.net/sevens nake/vqbvn vh2/2/
Ok I want to get the value from result modelstate and result2 model state. either example will work.
Ok I want to get the value from result modelstate and result2 model state. either example will work.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I kind of figured to use a object. good job. Thanks
Looks like your mytext assignment has missing quote (')
When you add these quotes, you have to properly escape occurence of quotes within string.
For example:
mytext ='{"Message":"The request is invalid.","ModelState":{"W
alert (mytext);