返回json数组的html表单

时间:2016-07-18 05:47:15

标签: javascript php jquery html node.js

这是我的简单html表单,它将传递用户名和密码并返回一个json数组

"message":{
    "attachment":{
      "type":"template",
      "payload":{
        "template_type":"generic",
        "elements":[
          {
            "title":"Classic T-Shirt",
            "image_url":"http://petersapparel.parseapp.com/img/item100-thumb.png",
            "subtitle":"Medium Grey %0D%0A s",
            "buttons":[
              {
                "type":"web_url",
                "url":"https://petersapparel.parseapp.com/view_item?item_id=100",
                "title":"View details"
              },
              {
                "type":"postback",
                "title":"Buy Now!",
                "payload":"USER_DEFINED_PAYLOAD"
              }              
            ]
          }
        ]
      }
    }
  }

这是我的路线:

 <form class="form-signin" id="login" method="post" action="/Webservices/0.1/login"">
  <input type="text" class="form-control" placeholder="email id" name="email" id="email">
  <input type="password" class="form-control" placeholder="Password" name="password" id= "password">
  <button  type="submit" name="submit" id="submit" >Sign in</button>
     </form>

此代码将返回一个json数组:

router.post('/login',function (req,res) {
    var email           = req.body.email;
    var password        = req.body.password;
    var arrayParam      =  [];
    var emailValidation = emailPattern.test(email);
    arrayParam.push('email','password');
    reqdParams.verifiyRequiredParameters(arrayParam, req.body, function (result) {
        if (result.success == "0") {
            res.json(result);
        }
        else if (email == '' || password == '' ) {
            res.json({'success': '0', 'result': {}, 'errorMessage': "data should not be null"});
        }
        else if (!(emailValidation)) {
            res.json({'success': '0', 'result': {}, 'errorMessage': 'not a valid email'});
        }
        else
        {   password =new Buffer(password).toString('base64');
            var userObject  = {'email':email, 'password': password};
            var  verifyUserQuery  = model.client.prepare("select userId,username,IFNULL(profilePicture,'') as profilePicture,email,password,profileType,IFNULL(profileId,'') as profileId,userType,IFNULL(token,'') as token,deviceName,osType,osVersion,isBlocked,isActive,ofActive,joinedDate from users where email = :email and password=:password");
            model.client.query(verifyUserQuery (userObject ),function(err,rows){
                if(rows.length> 0){
                    if(rows[0].isActive == 1){
                        var userProfile = rows[0];
                        res.json({'success':'1','result':{'message':'Valid User','userProfile':userProfile},'errorMessage':'No'});
                    }
                    else{
                        res.json({'success':'0','result':{},'errorMessage':'user is not verified'});
                    }

                }
                else
                    res.json({'success':'0','result':{},'errorMessage':'user Invalid'});
            });
        }
    });

});

if {"success":"0","result":{},"errorMessage":"user Invalid"} 我希望以html格式显示错误消息。

如果success=0我想重定向到另一个页面。

怎么做?

1 个答案:

答案 0 :(得分:0)

<div id="errorholder"></div>

HTML

if($ParID -lt 6) {
        $specific_error = "Par ID is is too short!"
    } else { #else 1
        if(!($ParID -match "[1-999999]")) {
            $specific_error = "Par ID must only contain numbers!"
        } else { #else 2

        }#else 2
    } #else 1