如何解码JSON javascript?

时间:2013-11-16 21:28:43

标签: javascript android cordova json

我是Phonegap和Javascript的新手。我正在尝试为android开发登录示例。我将Post方法的用户名和密码发送到php文件并获取此json编码输出

{"tag":"login","success":"1","error":"0"},"name":"can","email":"can@can.com"}}

这是我的客户端代码

<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script>



    <div style="padding:3px 2px;border-bottom:1px solid #ccc">Ajax Form</div> 
    <form id="ff" action="http://mehmetcantas.info/ogdtek/balance/index.php" method="post">

<table>
<tbody><tr>
<td>username : <input id="email" name="email" type="text"></td>
</tr>
<tr>
<td>password : <input id="password" name="password" type="password"></td>

</tr>
<tr>
<td><input type="hidden" name="tag" value="login"> </td>
</tr>
<tr>
<td>AffiliateLink : <input id="AffiliateLink" name="AffiliateLink" type="text"></td>
</tr>


<tr><td><input value="Submit" type="submit"></td>

</tr></tbody></table>
</form>
<script type="text/javascript">
$('#ff').form({ 
    success:function(data){ 
        $.messager.alert('Info', data, 'info'); 
    } 

});
</script>

如果成功我想做:1然后打开welcome.html

1 个答案:

答案 0 :(得分:1)

这可能适合你。

if (data.succes == '1') {
   window.location="welcome.html";
}
else {
   window.location="login.html";
}

PS:你提供的json无效。

{"tag":"login","success":"1","error":"0"},"name":"can","email":"can@can.com"}}

IT应如下所示。

{"tag":"login","success":"1","error":"0","name":"can","email":"can@can.com"}