如何从javascript到vb asp.net获取表单?
我在javascript中创建一个表单并将其发送到vb asp.net端。
如何在vb asp.net中获取javascript表单值?
现在getclienttoken什么都不打印。该变量中没有任何值。
vb asp.net代码
Protected Sub Page_load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
Dim nvc As NameValueCollection = Request.Form
Dim GetClientToken As String = nvc("token")
Label1.Text = "flag1" & GetClientToken
End If
End Sub
javascript代码:
<script type="text/javascript">
...
var form = document.querySelector('form');
form.querySelector('input[name="token"]').setAttribute('value', result.token.id);
form.submit();
...
</script>
html代码:
<input type="hidden" name="token" />
<div class="group">
<label>
<span>Card number</span>
<div id="card-number-element" class="field"></div>
</label>
<label>
<span>Expiry date</span>
<div id="card-expiry-element" class="field"></div>
</label>
<label>
<span>CVC</span>
<div id="card-cvc-element" class="field"></div>
</label>
<label>
<span>Postal code</span>
<input id="postal-code" name="postal_code" class="field" placeholder="90210" />
</label>
</div>
<button type="submit">Pay</button>
答案 0 :(得分:0)
一些可能性:
result.token.id
; If Not IsPostBack Then
应被删除 - 此块中的代码只会在首次加载时触发,而不会在此之后触发。