PHP 和jquery:渐进增强
我有几个 php 页面,其中有用于提交数据的表单。我的典型设置是让页面发布到自身,以便我可以验证输入,并在必要时使用用户提交的数据(以及显示错误所在的标记)重新加载页面。如果一切正常,我将重定向到感谢页面。
我想开始使用 ajax (jquery) 提交表单,但如果客户端不使用 javascript,则可以使用原始的 php 提交。我对 jquery 还很陌生,并且发现了几个使用 jquery 提交的示例,但没有一个使用我上面描述的设置。如果可能的话,有人可以给出一个简短的例子或指出一个页面。谢谢
I have several php pages that have forms used to submit data. My typical setup is to have the page post to itself so that I can validate the input and if necessary reload the page with the user submitted data (and markup to show where the error is). If everything is OK I redirect to a thank you page.
I would like to start using ajax (jquery) to submit the forms, but have the original php submit to fall back on incase the client is not using javascript. I'm still very new to jquery and have found several examples to submit using jquery but none using the setup I described above. If possible could someone give a brief example or point to a page that does. Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以在此处使用 jquery 表单插件 http://jquery.malsup.com/form/
这将是转换现有页面的简单方法。
You could possibly use the jquery form plugin here http://jquery.malsup.com/form/
that would be an easy way convert existing pages.
您可以使用 POST 方法通过 jQuery 提交 POST 数据:
示例脚本可能如下:
You can submit POST data with jQuery by using the POST method:
An example-script may be the following:
如果响应正常,则 $.post 回调中的 window.location.href =thankyou_page_url 。
window.location.href = thankyou_page_url in your $.post callback if the response is OK.