【问题标题】:Preventing my form to refresh using ajax使用ajax防止我的表单刷新
【发布时间】:2018-02-26 08:59:52
【问题描述】:

大家好,我只是想问一下如何制作 ajax 以防止在我的 html 表单页面中加载页面我想要阻止加载的输入是带有提交类型和提交值的按钮标签

在我的例子中,这是我的 html 代码:

            <div class="one">
                <label>living room<span></span></label>
                    <div><button type="submit" name="submit" id="one" class="test_1"  value="one"><p>Click On</p></button></div>    </div>
                    <div class="one"><li><button type="submit" name="submit" id="two" class="test_2" onmousedown="beepoff.play()" value="one_off">Click Off</button></li></div>


            <div class="one">
                <label>kitchen</label>
                    <button type="submit" name="submit" id="one" class="test_1"  value="two">Click On</button>
                </div>
                    <div class="one">
                        <button id="two" type="submit" name="submit" class="focus_one test_2"  value="two_off">Click Off</button>
                    </div></form>

【问题讨论】:

标签: javascript php html


【解决方案1】:

您可以在提交功能被触发时使用e.preventDefault()

function onSubmit(e){
   e.preventDefault()
   .... rest of code
}

【讨论】:

  • 你应该编辑你的问题添加你的代码,因为这是一个常见的问题,已经被问过很多次了。
  • 这是我的html表单结构,它调用要执行的php函数,这是函数 //// shell_exec('java -jar DenkoviRelayCommandLineTool.jar DAE003wK 8 1 1'); /// 我将它用于我们的项目家庭照明自动化
【解决方案2】:

最简单的方法是使用带有按钮类型的按钮,这样不会提交表单。

<button type='button'>Text here</button>

【讨论】:

    猜你喜欢
    • 2018-10-28
    • 1970-01-01
    • 1970-01-01
    • 2020-03-17
    • 1970-01-01
    • 1970-01-01
    • 2017-03-14
    • 1970-01-01
    • 2021-09-30
    相关资源
    最近更新 更多