简体   繁体   English

如何在 AJAX 中模拟按钮单击

[英]How to simulate a button click in AJAX

I am writing a program that should simulate clicking on submit in AJAX, after which the page should asynchronously reload.我正在编写一个程序,它应该模拟点击 AJAX 中的提交,之后页面应该异步重新加载。 I wrote a program, that asynchronously reloads the page, but only if I click on the submit button.我写了一个程序,异步重新加载页面,但前提是我点击提交按钮。

Here is my program:这是我的程序:

$("#form_id").submit(function() {
    var str = $(this).serialize();
    $.ajax({
        type: "POST",      
        url: "../async_db.php",
        data: str,
        success: function(html) {
            $('#d_id').html(html);
        }
    });
    return false;
});

To reload a page after post data by ajax asynchronously you can use location.reload() at the end of the submit() function.要在 ajax异步发布数据后重新加载页面,您可以在submit() function 末尾使用location.reload()

  $("#form_id").submit(function() {
                    var str = $(this).serialize();
                    $.ajax({
                        type: "POST",      
                        url: "../async_db.php",
                        data: str,
                        success: function(html) {
                            $('#d_id').html(html);
                        }
                    });
                    return false;
                    location.reload();
                });

如何模拟点击<div role="“button”"> ?</div><div id="text_translate"><p> 我在 web 页面上有一个元素。</p><pre> &lt;div class="profile-action profile-action--lg profile-action--color-yes profile-action--filled js-profile-header-vote-yes js-profile-header-vote" data-choice="yes" role="button"&gt; &lt;div class="profile-action__icon"&gt; &lt;i class="icon icon--stretch"&gt; &lt;svg class="icon__svg"&gt; &lt;use xlink:href="#floating-action-yes"&gt;&lt;/use&gt; &lt;/svg&gt; &lt;/i&gt; &lt;/div&gt; &lt;/div&gt;</pre><p> 我正在尝试通过以下代码模拟点击事件。</p><pre> document.getElementsByClassName("js-profile-header-vote-yes")[0].click()</pre><p> 它不会模拟对该元素的任何点击。 我究竟做错了什么?</p><p> 编辑:我已经尝试过 jQuery 和 dispatchEvent,它们也不起作用。 我也试过 selenium,它可以工作,但这不是我想要的。</p><p> Edit2:我不想处理点击事件,我想模拟点击方法。</p></div> - How to simulate click on <div role=“button”>?

暂无
暂无

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

相关问题 如何使用参数模拟单击按钮 - How to simulate a click button with parameters 如何模拟点击Kendoui按钮 - How to simulate click on Kendoui button 如何在Facebook分享按钮上模拟点击事件 - how to simulate the click event on the facebook share button 如何模拟图像按钮的单击 - How to simulate an image-button click 如何通过单击 Javascript 的按钮来模拟按键? - How to simulate keypress with a button click on Javascript? 如何模拟点击<div role="“button”"> ?</div><div id="text_translate"><p> 我在 web 页面上有一个元素。</p><pre> &lt;div class="profile-action profile-action--lg profile-action--color-yes profile-action--filled js-profile-header-vote-yes js-profile-header-vote" data-choice="yes" role="button"&gt; &lt;div class="profile-action__icon"&gt; &lt;i class="icon icon--stretch"&gt; &lt;svg class="icon__svg"&gt; &lt;use xlink:href="#floating-action-yes"&gt;&lt;/use&gt; &lt;/svg&gt; &lt;/i&gt; &lt;/div&gt; &lt;/div&gt;</pre><p> 我正在尝试通过以下代码模拟点击事件。</p><pre> document.getElementsByClassName("js-profile-header-vote-yes")[0].click()</pre><p> 它不会模拟对该元素的任何点击。 我究竟做错了什么?</p><p> 编辑:我已经尝试过 jQuery 和 dispatchEvent,它们也不起作用。 我也试过 selenium,它可以工作,但这不是我想要的。</p><p> Edit2:我不想处理点击事件,我想模拟点击方法。</p></div> - How to simulate click on <div role=“button”>? 如何在 CodeMirror 中通过单击按钮来模拟按键? - How to simulate a keypress with button click in CodeMirror? 如何模拟按住按钮类的点击 - How to simulate a hold click on a button class 模拟点击javascript按钮 - Simulate click of javascript Button 在 Jest 中模拟按钮单击 - Simulate a button click in Jest
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM