我有一个这样的表格:
<form name="paymentForm" id="paymentForm" action="/submit.jsp" method="post">
<fieldset id="ccData">
<input id="ccNumber" name="ccNumber"/>
</fieldset>
<fieldset id="otherData">
<input id="requestId" name="requestId"/>
</fieldset>
</form>
当您提交提交时,我想(通过ajax)仅将#ccData字段集提交给某个不同的网址(例如submitCC.jsp),并根据回复我想将完整格式提交到实际网址。
我怎样才能做到这一点?
答案 0 :(得分:2)
使用jQuery的serialize方法
var formData = $("#ccData").serialize();
$.post("TheUrl",formData);
答案 1 :(得分:0)
你可以用JavaScript做到这一点 - 例如jQuery。您构建了一个类似
的eventHandler$('#paymentForm').on('click', function () {
$(this).preventDefault();
if ($(this).hasClass('first_send')) {
$.ajax({
url: "your_url",
data: { ccData: $('#ccData').val()}
}).done(function ( data ) {
$('#paymentForm').addClass('first_send')
// examin the data, insert stuff you need and send the form again
// with ajax
})
} else {
$(this).removeClass('first_send')
// this is the second send - so do stuff here - show a result or so
}
})
使用first_send类,您可以检查它是第一个发送还是第二个发送。这只是一个未经测试的,不完整的想法,你怎么能做到这一点。我想你得到了全局......