を使用した簡単な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