由网友(无法释怀那夜妖娆的你╮)分享简介:我停留在我的code,我需要从表单发送数据到check.php页面,然后对其进行处理。这是我的code:AJAX的部分:<脚本SRC =http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js>< / SCRIPT&GT ;...
我停留在我的code,我需要从表单发送数据到check.php页面,然后对其进行处理。
这是我的code:
AJAX的部分:
<脚本SRC =http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js>< / SCRIPT&GT ;
<脚本>
$(文件)。就绪(函数(){
变种形式= $(#myForm会);
$(#SMT)。点击(函数(){
$阿贾克斯({
键入:POST,
网址:form.attr(行动),
数据:form.serialize(),
成功:函数(响应){
的console.log(响应);
}
});
});
});
< / SCRIPT>
形式:
<形式的行动=check.php方法=邮报NAME =myForm的ID =myForm的>
<输入类型=文本名称=用户ID =用户/>
<输入类型=文本名称=通行证ID =通/>
<输入类型=按钮NAME =SMTVALUE =提交ID =SMT/>
< /形式GT;
< DIV ID =犯错>< / DIV>
PHP的一部分:
$用户= $ _ POST ['用户'];
$传球= $ _ POST ['传球'];
如果($用户==托尼)
{
回声HI$用户。
}
其他
{
回声我不认识你。
}
解决方案
试试这个
$(文件)。就绪(函数(){
变种形式= $(#myForm会);
$(#SMT)。点击(函数(){
$阿贾克斯({
键入:POST,
网址:form.attr(行动),
数据:$(#myForm会输入)序列化(),//只输入
成功:函数(响应){
的console.log(响应);
}
});
});
});
I am stuck in my code, I need to send data from the form to the check.php page and then process it.
This is my code:
The AJAX part:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
var form=$("#myForm");
$("#smt").click(function(){
$.ajax({
type:"POST",
url:form.attr("action"),
data:form.serialize(),
success: function(response){
console.log(response);
}
});
});
});
</script>
The form:
<form action="check.php" method="post" name="myForm" id="myForm">
<input type="text" name="user" id="user" />
<input type="text" name="pass" id="pass" />
<input type="button" name="smt" value="Submit" id="smt" />
</form>
<div id="err"></div>
the php part:
$user=$_POST['user'];
$pass=$_POST['pass'];
if($user=="tony")
{
echo "HI ".$user;
}
else
{
echo "I dont know you.";
}
解决方案
Try this
$(document).ready(function(){
var form=$("#myForm");
$("#smt").click(function(){
$.ajax({
type:"POST",
url:form.attr("action"),
data:$("#myForm input").serialize(),//only input
success: function(response){
console.log(response);
}
});
});
});
相关推荐
最新文章