我想使用这个表单提交数据到数据库,如何配置ajax和PHP相关参数,我租的WEB空间是PHP的,我要实现的目的是收集报名信息,数据库能查询即可。当点击页面提交的时候,会弹出信息:您已经报名成功!稍后会有助教与您联系“我好久都没有接触层序了,好久都没有上来了,这里因页面需要现改模板网页,却不知道如何配置。没有分了,没办法给分,对不起!拜托懂得朋友帮忙指点指点。非常感谢
<td align="center"><form action="" method="post" name="forma" id="forma" onsubmit="return checkform();">
<input type="hidden" name="action" value="save">
<table width="431">
<tbody>
<tr>
<td width="91" height="20" align="right"><font color="#000000"><font color="#ff0000">*</font>联系人:</font></td>
<td width="328" height="44"><input class="text" id="linkman" size="28" name="linkman"></td>
</tr>
<tr>
<td align="right" height="18"><font color="#000000"><font color="#ff0000">*</font>手机:</font></td>
<td height="44"><input class="text" id="phone" size="28" name="phone"></td>
</tr>
<tr>
<td height="42" colspan="2" align="center"><input class="btn" type="submit" value=" 点 击 报 名 " name="Submit"></td>
</tr>
</tbody>
</table>
</form></td>
你没有写过js吗? 那应该学一下ajax教程的。使用jquery的ajax就可以了。
表单提交action,不需要ajax,表单中包含name属性的input数据,会自动添加到请求中; 你可以学一下 form表单
这个网站很不错: http://www.w3school.com.cn/b.asp
参考 http://www.w3school.com.cn/jquery/jquery_ref_ajax.asp
jquery的ajax例子大概是这样:
$.post(url,{name:"john",phone:"120"},function success(data, textStatus, jqXHR){
// 弹出提示
});
ajax是不用配置的,你可以用原生的JavaScript来写ajax也可以用jquery的封装好的$.ajax()
和空间无关,ajax是客户端的,和你表单提交差不多,只是ajax不会刷新页面,表单会。。
<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.4.2.min.js"></script>
<script>
function checkform() {
//....你原来的验证
$.ajax({ url: 'xxxx.php', data: $('#forma').serialize(), type: 'POST', complete: function (xhr) {
alert('请求完毕,服务器返回\n'+xhr.responseText)
} });
}
</script>
<td align="center"><form action="" method="post" name="forma" id="forma" onsubmit="return checkform();">
<input type="hidden" name="action" value="save">
<table width="431">
<tbody>
<tr>
<td width="91" height="20" align="right"><font color="#000000"><font color="#ff0000">*</font>联系人:</font></td>
<td width="328" height="44"><input class="text" id="linkman" size="28" name="linkman"></td>
</tr>
<tr>
<td align="right" height="18"><font color="#000000"><font color="#ff0000">*</font>手机:</font></td>
<td height="44"><input class="text" id="phone" size="28" name="phone"></td>
</tr>
<tr>
<td height="42" colspan="2" align="center"><input class="btn" type="submit" value=" 点 击 报 名 " name="Submit"></td>
</tr>
</tbody>
</table>
</form></td>
$.getJSON('ajax.php?'+$("#forma").serialize()+'&jsoncallback=?');