現在のページを更新する必要がないように、iframe を使用できます。
多くの人がプラグインに直行します。しかし、これは非常に簡単に行うことができ、AJAX リクエストのすべての機能を使用できます。
ロード イベント ハンドラーがアタッチされている非表示の iframe にフォームを送信して、フォームが送信されると、サーバーの応答 (ロード後の iframe の HTML) を実際に含むコールバック関数を使用します。
例:
<form action="..." method="post" encrypt="application/x-www-form-urlencoded" target="workFrame" >
<input type="file" name="file" />
<input type="submit" />
</form>
<iframe id="workFrame" src="about:blank" style="display:none;"></iframe>
Javascript コードは次のとおりです。
(function () {
$('form').on('submit', function () {
//check if the form submission is valid, if so just let it submit
//otherwise you could call `return false;` to stop the submission
});
$('#workFrame').on('load', function () {
//get the response from the server
var response = $(this).contents().find('body').html();
//you can now access the server response in the `response` variable
//this is the same as the success callback for a jQuery AJAX request
});
});