テキストフィールドのペアで構成されるフォームがあります。ユーザーは、必要な数のペアを作成してフィールドに入力できます。フィールドの行がテーブルの下部に追加されます。フォーマットのサンプルは次のとおりです。
<form id="dataForm">
<table id="textTable">
<tbody>
<tr>
<td><h2>Dancer</h2></td>
<td><h2>Place</h2></td>
</tr>
<tr>
<td><input type="text" name="Dancer0" size="15" id="Dancer0"></td>
<td><input type="text" name="Place0" size="15" id="Place0"></td>
</tr>
<tr>
<td><input type="text" name="Dancer1" size="15" id="Dancer1"></td>
<td><input type="text" name="Place1" size="15" id="Place1"></td>
</tr>
</tbody>
</table>
<input type="button" id="newRow" value="New Row" accesskey="/" onclick="moreFields();">
<input type="button" value="Update" name="Submit" onclick="submitForm(this.form);">
</form>
私が抱えている問題は、ajaxを使用してフォームを外部のphpページに適切に送信することです。これは私が今使っている関数です:
function submitForm(form)
{
jQuery.ajax({
type: "POST",
url: <?php echo '"'.dirname(curPageURL()).'/ResultsUpdater.php"' ?>,
data: form.serialize(),
success: function(msg){
alert(msg);
}
});
return false;
}
他の例では、jQueryを表すために$を使用し、「form」の前に配置されるのを見てきました$(form).serialize()
が$.ajax({...
、私のサーバーは。を好みません$
。私も試しましjQuery.form.serialize()
たが、それもうまくいきません。コンソールで発生するエラーは、常に次のようなものです。"TypeError: 'undefined' is not an object (evaluating 'jQuery.form.serialize')"
たくさんのキーと値のペアをphpファイルに送信できれば(serialize()が理解していることから)、それは素晴らしいことです。
こちらのフォームをお試しいただけます
ドロップダウンアイテムの1つを選択するだけで、フォームが表示されます。
ありがとう