简体   繁体   English

通过Ajax问题提交表单

[英]Submitting a form via Ajax issue

I have a page that dynamically generates a list of items, in each one of those items is a button that submits a from containing data from that item in the list (that is sorted and working). 我有一个页面可以动态生成项目列表,在每个项目中都有一个按钮,用于提交一个包含列表中该项目的数据的列表(已排序且有效)。 I submit the form via this code (Jquery): 我通过以下代码(Jquery)提交表单:

<script type="text/javascript" src="./js/jquery.form.js"></script>
<script type="text/javascript">
    $('document').ready(function(){
        $('#readlatersubmit').ajaxForm( {
            target: '#result', 
            success: function() { 
                //$('#readlatersubmit').fadeOut('1000');   
                //$("#loader").fadeOut(); 
            } 
        }); 
        return false;
    });
</script>

When I click the button it submits the correct data and without the refreshing the whole page. 当我单击按钮时,它将提交正确的数据,而不会刷新整个页面。 The problem is that if I then go and click another one of the buttons in another one of the list items it goes to the form process page (does not submit via the Jquery). 问题是,如果我随后去单击列表项中另一个列表项中的另一个按钮,它将转到表单处理页面(不通过Jquery提交)。

Does anyone know how I can fix this issue? 有谁知道我该如何解决这个问题?

Edit This is what my form currently looks like: 编辑这是我的表单当前的外观:

<form id='readlatersubmit' action='RL.php' method='post'>
    <input type='hidden' name='RLURL' value='".$item->get_link()."'/>
    <input type='hidden' name='RLTitle' value='".$item->get_title()."' />
    <input type='hidden' name='user-id' value='$loggedInUser->user_id' />
    <input type='image' src='images/ReadLaterRibbon_Active.png' name='submit' value='Submit' class='button' />
</form>
<div id='result'></div>

Remove return false and let it check. 删除return false并进行检查。 because when you click on submit once, this will hold you on false but you don't need false, just remove return or use return true, 因为当您单击一次提交时,这将使您处于错误状态,但是您不需要错误,只需删除return或使用return true,

    <script type="text/javascript" src="./js/jquery.form.js"></script>
<script type="text/javascript">
   function doitRun() {
        $('#readlatersubmit').ajaxForm( {
            target: '#result', 
            success: function() { 
                //$('#readlatersubmit').fadeOut('1000');   
                //$("#loader").fadeOut(); 
            } 
        }); 
   }
</script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM