から投稿データを空のアクションで送信し、投稿情報を処理する必要があるファイルに javascript で情報を送信しようとしています。
これが私のコードです:
<HTML>
<head>
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
</head>
<script>
function post_to_url(path, params, method) {
method = method || "post";
var form = document.createElement("form");
form._submit_function_ = form.submit;
form.setAttribute("method", method);
form.setAttribute("action", path);
for(var key in params) {
var hiddenField = document.createElement("input");
hiddenField.setAttribute("type", "hidden");
hiddenField.setAttribute("name", key);
hiddenField.setAttribute("value", params[key]);
form.appendChild(hiddenField);
}
document.body.appendChild(form);
form._submit_function_();
}
post_to_url("./postinfo.php", { submit: "submit" } );
</script>
<form method="post" onsubmit="return post_to_url()">
<input type="text" name="ime">
<input type="submit" id="submit" name="submit" value="Send">
</form>
postinfo.php
では、HTMLフォームで空のアクションを使用してjavascriptを使用して投稿データを送信するにはどうすればよいですか?
前もって感謝します!