在https上使用json自动登录
  可能重复: 
  使用jQuery将表单数据转换为JS对象 
我需要将我的用户登录到外部网站,但出现问题,本网站仅处理json-data POST值,例如。 { “用户名”: “用户”, “密码”: “12345”}
<form action="https://external.com/login" method="POST">
<input name="username" value="user" />
<input name="password" value="12345" />
<input type="submit" />
</form>
这上面只发送平均key = value数据,我怎样才能使用POST json-data到外部https?
  这是一个简单的jQuery示例,使用jQuery.ajax() 
HTML:
<form action="https://external.com/login" method="POST" onsubmit="return postJson(this)">
<input name="username" value="user" />
<input name="password" value="12345" />
<input type="submit" />
</form>
JQ:
function postJson(form) {
    var action = $(form).attr('action');
    var user = $('[name="username"]', form).val();
    var pass = $('[name="password"]', form).val();
    console.log('action=' + action + ', user=' + user + ', pass=' + pass);
    $.ajax({
        url: action,
        type: 'POST',
        data: JSON.stringify({ username: user, password: pass }),
        success: function(data, status) {
            // do something after login
            console.log('success');
        },
        error: function() {
            console.log('error');
        }
    });
    return false;
}
的jsfiddle
链接地址: http://www.djcxy.com/p/46339.html