点击/提交提交按钮时如何执行第一个PHP函数,然后执行JavaScript函数

3

i have this input field:

<input type="submit"  name="rregjistro" value="Rregjistro Tani Te Dhenat" onclick="openmodal()" >

我希望首先在PHP中执行POST脚本,然后使用JavaScript函数打开一个模态弹窗。

你能帮我吗!提前感谢你!


5
考虑使用 Ajax。 - utdev
5
运行Ajax查询。然后在回调中打开弹出窗口。 - user4035
2个回答

4

使用PHP无法进行点击操作,因为表单提交是在客户端完成的,即在您的浏览器中完成。浏览器中的此类事件可以通过JavaScript或其他客户端语言执行。

<form ... >
<input type="submit"  name="rregjistro" value="Rregjistro" />
<!-- remove onclick attribute for now -->

</form>

<div id="myResult"></div>

<script>
$(function(){
    $("input[name=rregjistro]").click(function(){
        // url needs to belong to your domain
        $.ajax({url: "/your_url_path", success: function(result){
            $("#myResult").html(result);
            open();
        }});
    });
});
</script>

0

你仍然需要首先编写一个 JavaScript 函数。

在 jQuery 中,可以这样写:

function open() {
  $.post('http://url', $('#form').serialize(), function() {
    alert('popup goes here');
  })
)

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接