我有一个表格,其中包含姓名,手机号码,电子邮件和城市。在提交表格时,我正在调用一个api。我需要调用一个API来检查电子邮件ID是否存在以及一个手机号码是否存在。我没有得到如何在输入更改时调用api。最好的方法是什么?预先感谢
答案 0 :(得分:0)
据我了解,最好的方法是使用uint16_t
属性->验证服务器上的字段->服务器以JSON格式的任何错误进行响应。
https://www.ampproject.org/docs/reference/components/amp-form#verification
verify-xhr
来自服务器的响应可以像:
<form
method="post"
action-xhr="/form/verify-json/post"
verify-xhr="/form/verify-json/post"
target="_blank">
<fieldset>
<label>
<span>Email</span>
<input type="text" name="email" required>
</label>
<label>
<span>Zip Code</span>
<input type="tel" name="zip" required pattern="[0-9]{5}(-[0-9]{4})?">
</label>
<input type="submit" value="Submit">
</fieldset>
<div submit-success>
<template type="amp-mustache">
<p>Congratulations! You are registered with {{email}}</p>
</template>
</div>
<div submit-error>
<template type="amp-mustache">
{{#verifyErrors}}
<p>{{message}}</p>
{{/verifyErrors}}
{{^verifyErrors}}
<p>Something went wrong. Try again later?</p>
{{/verifyErrors}}
</template>
</div>
</form>