PDA

View Full Version : When the response is not JSON



lehoangel
14 Mar 2011, 10:50 PM
Hi I'm doing a simple login form. And this is the configuration for button [Login]



buttons: [{
text:'Login',
handler: function(){
loginForm.getForm().submit({
url: 'loginAction',
success: function(){
alert('success');
window.location = '/mfm/pages/loginAction';
},
failure: function(){
alert('fail');
}
});
}
}]The problem is the loginAction is configured using tiles & struts, like this:


<action name="loginAction" class="homeAction" method="login">
<result name="SUCCESS" type="tiles">homePage</result>
</action>When this action is called, it responses a html page, not a JSON type with a proper form like
{success: true, data: xxx}.
So, the failure function is called instead of success function.

I wonder if there is any way to make a suitable return in this case, or at least, make the extjs understand that it should run success function. :-?:-?:-?
Thanks.

todic
14 Mar 2011, 11:54 PM
When this action is called, it responses a html page, not a JSON type with a proper form like
{success: true, data: xxx}.
So, the failure function is called instead of success function.

As far as I know, response doesn't have to be JSON. There is no reason why it should. So, your problem is something else.

Try using "firebug" (firefox addon) and make sure that your request has been made and that response is successfully received. Most probably the problem is within some of this two.

lehoangel
15 Mar 2011, 1:12 AM
Thank to your helping :D, I've already found the problem. It returns fail because the HTML lacks of some end tags, which is must in XML (type a response data). Now it runs the success function, but I still don't know why it could understand it's successful action when I don't have any configure like {success:true, data: xxx. :-?

lehoangel
15 Mar 2011, 11:26 PM
Still confused about the XML response.

This is what the action response:


<html>
<head>
<title>Moon Fleet Management</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link href="/mfm/css/ext-all.css" rel="stylesheet" type="text/css" />
<link href="/mfm/css/xtheme-gray.css" rel="stylesheet" type="text/css" />
<style type="text/css">
#loginForm {
width: 400px;
display: block;
margin: 100px auto;
}
</style>
<!----- JS ----->
<script type="text/javascript" src="/mfm/js/extjs/ext-base.js"> </script>
<script type="text/javascript" src="/mfm/js/extjs/ext-all-debug.js"> </script>
</head>
<body>
....
</body>
</html>
And this is the error that firebug found:

missing } in XML expression
width: 400px;\n
Could u explain it for me?

todic
16 Mar 2011, 1:07 AM
Oh, well then your problem has nothing to do with ExtJs.

Your XML is malformed. You're supposed to put your css definition into CDATA section. Example:

<style type="text/css"><![CDATA[
#loginForm {
width: 400px;
display: block;
margin: 100px auto;
}
]]

This is because xml parser by default parse your CSS code(and everything else) as XML.

lehoangel
16 Mar 2011, 2:00 AM
Thank you a lot! :)