English 中文(简体)
$ $ $ $ posts jquery 提交我的表格
原标题:$posts jquery submits my form
<script type="text/javascript">
    function claim()
    {
        var c = confirm( You sure? );

        if(c)
        {
            var password=prompt("Please mention pw","");
            if (password!=null && password!="")
              {
                    $.post("/claim/<?php echo $refnr; ?>", { partner_pwd: password },
                       function(data) { 
                            alert(data);
                            if(data ==  1 )
                            {
                                return true;
                            }else{
                                return false;
                            }
                       });
              }else{
                return false;
              }
        }else{
            return false;
        }
    }
</script>

当测试时,我得到请提及pw, 在我输入并按好后, 它提交我的表格, 而不是制作$. post, 只有在数据 = 1 (返回真实) 时才提交我的表格

索赔()按我的提交按钮调用;

<input type="submit" name="submit" onclick="return claim()"; value="Submit" />

我尝试了警示调试 就像我以为当它读到$. post () 时它会自动提交一样, 我只希望它提交(通过返回真实) 如果数据是 1, 我只希望它提交(通过返回真实) 。

最佳回答

return true return freed 在您的 $. post 请求中除了返回外什么都不做。 它不妨碍表格提交。 相反, 如果您想要提交, 请尝试完全防止提交, 然后触发它 。

function claim() {
    var c = confirm( You sure? );

    if (!c) {
        return false;
    }

    var password = prompt("Please mention pw", "");
    if (password != null && password != "") {
        $.post("/claim/<?php echo $refnr; ?>", {
            partner_pwd: password
        }, function(data) {
            alert(data);
            if (data ==  1 ) {
                $("#myform").submit();
            }
        });
    }
    return false;
}​

注意我们如何从该函数中退出 ways return freed , 不论有效性如何。 如果该函数有效, 我们直接触发窗体提交事件 。

问题回答

好吧,如果你在网站上填写表格, 目标是提交表格。

< a href=" "http://api.jquery.com/submit/" rel="no follow" > (从 开始,缩到最后一个例子:如果你想防止提交表格,除非设置了国旗变量,请尝试: )

如上面的链接所示, 您应该更改窗体动作, 而不是某页, 并做一些类似 < code > action= > " javascript: claim () 的动作。 我认为这应该有效 。

您在提交器上点击方法无效, 因为表格在任一方向都会被提交 。

You should for example set a listener on the onsubmit(); event on the form or another solution is on the put the onsubmit attribute with your javascript function in it and submit the form from your javascript with the $( #form ).submit(); function.





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签