AJAX和PHP表单验证不起作用 [英] AJAX&PHP form validation doesn't work

查看:194
本文介绍了AJAX和PHP表单验证不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近学会了如何使用AJAX,但我遇到了问题。我要做的是用PHP验证表单,并在同一页面中写入验证的输出。从我在bytes.com中提出的最后一个问题开始,我被介绍给了AJAX(好吧,我一直都知道它,但我从未使用它)。所以,我相应地编写了以下代码:


index.html:

Hi, I recently learned how to use AJAX, but I''m having a problem with it. What I''m trying to do is validate a form with PHP, and write the output of the validation in the same page. From the last question I have asked in bytes.com, I was introduced to AJAX(well, I always knew it, but I never used it). So, I wrote the following code accordingly:

index.html:

展开 | 选择 | 换行 | 行号

推荐答案

有几个问题:


- index.html#49。无论getObject()做什么,在完成后表单将提交,页面重新加载,因此没有可见的JavaScript输出。


- main.js#46。 DOM-0事件处理程序需要传递函数,而不是函数返回值。即 http.onreadystatechange = getServer;


感谢您的回复!


怎么可能我用getObject()解决了这个问题,这样我就可以按照我想要的方式(在同一页面中)显示我想要的内容。我知道这是一个简单的问题,但我不太熟悉AJAX的工作原理:P
Thanks for the reply!

How could I fix the problem with getObject() so that I will be able to display what I want, the way I want(in the same page). I know this is a simple question, but I''m not very familiar with how AJAX works :P


使用单击按钮或阻止表单提交(通过阻止默认动作或通过事件属性显式返回false)
either use a click button or prevent the form from submitting (either by preventing the default action or by explicitly returning false from the event attribute)


这篇关于AJAX和PHP表单验证不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆