[英]Jquery form submission is not working
I try to submit a form after my ajax request done. 我尝试完成ajax请求后提交表单。 I do code like following.
我做如下代码。 But when I click the button ajax request is go to and send 200 ok feedback.
但是,当我单击按钮ajax请求时,请转到并发送200 OK反馈。 But after that form not submit.
但是在该表格之后不提交。 What is wrong on this code?
此代码有什么问题?
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script>
$('document').ready(function(){
$('#submit').on('click',function(){
$.post('cart.php',{email:'email',pkgname:'pkgname'}).then(function(){
$('form').submit();
});
});
});
</script>
</head>
<body>
<form action="cart.php" method="post">
<input type="button" id="submit" value="submit" />
</form>
</body>
</html>
try to build the $.post
request like: 尝试构建
$.post
请求,例如:
$.post('cart.php', {email:'email',pkgname:'pkgname'}, funtion(data){
console.log(data);//return the data from server if anything echoed in cart.php file
})
where data
contains what cart.php
returns (i cannot understand why you are sending the form twice anyway) data
包含cart.php
返回的内容(无论如何我都不明白为什么要发送两次表单)
I update code as below and I think it is not getting response from sever I think u update this and check you will get your problem : 我更新代码如下,我认为它没有得到服务器的响应,我想你更新此并检查你会得到你的问题:
$('document').ready(function(){ $('#submit').on('click',function(){ $.post('cart.php',{email:'email',pkgname:'pkgname'}).success(function(data){ $('form').submit(); }).error(alert("Code has error")); }); });
Here answer for my question. 在这里回答我的问题。 I don't know how is this possible???
我不知道这怎么可能??? :( My submit button id is the cause for my question. You never ever use #submit as a ID. It will be a problem!! This bugger wast my two days!!
:(我的提交按钮ID是我提出问题的原因。您永远不会使用#submit作为ID。这将是一个问题!
So correct code is 所以正确的代码是
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script>
$('document').ready(function(){
$('#submit1').on('click',function(){
$.post('cart.php',{email:'email',pkgname:'pkgname'}).then(function(){
$('form').submit();
});
});
});
</script>
</head>
<body>
<form action="cart.php" method="post">
<input type="button" id="submit1" value="submit" />
</form>
</body>
</html>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.