$ .post只能使用警报 [英] $.post work only with alert
问题描述
函数post(){
var cvs = $ ( '#客户-NBR')VAL();
var cs = $('#cs')。val(); $ .post('a.php'{postcvs:cvs,postch1:cs});
alert(功能工作);
}
和这样的html表单:
< form action =b.phpmethod =postonsubmit =return post()>
问题是当我从函数中删除警告$ .post不起作用时:
function post(){
var cvs = $('#client-nbr')。val();
var cs = $('#cs')。val(); $ .post('a.php'{postcvs:cvs,postch1:cs});
}
请帮忙:)
由于 post()
没有 return
语句, onsubmit
函数最终返回 undefined
。
由于它不返回 false
,它不会取消表单的正常行为。因此,表单在Ajax请求解决之前提交并卸载页面。
放入警报
会延迟页面直到您点击确定,这会给Ajax请求解决时间。
return false
post 函数来取消表单的正常提交。
When i call function with alert is working parfectly :
function post() {
var cvs = $('#client-nbr').val();
var cs = $('#cs').val(); $.post('a.php' {postcvs:cvs,postch1:cs});
alert("The function work");
}
And the html form like this :
<form action="b.php" method="post" onsubmit="return post()">
The problem is when i remove alert from function the $.post doesnt work :
function post() {
var cvs = $('#client-nbr').val();
var cs = $('#cs').val(); $.post('a.php' {postcvs:cvs,postch1:cs});
}
Pls help :)
Since post()
doesn't have a return
statement, the onsubmit
function ends up returning undefined
.
Since it doesn't return false
, it doesn't cancel the normal behaviour of the form. Consequently, the form submits and unloads the page before the Ajax request resolves.
Putting in an alert
delays the page unload until you click OK, which gives time for the Ajax request to resolve.
return false
from the post
function to cancel the normal submission of the form instead.
这篇关于$ .post只能使用警报的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!