$.ajax 不起作用并在 onclick 事件中绕过



我的onclick事件没有调用ajax请求,但是函数给了我第一个和第二个警报。这是我的代码。

 function interaction()
    {
        alert('first');
        $.ajax({
                    url: "store_setting_ajax.php",
                    dataType:'json',
                    type:'POST',
                    data:{
                        interaction1:'yes'
                    },
                    success:function(data){
                        window.location.reload();
                    }
                });
       alert('second');
    }

我尝试e.preventDefault()但不起作用。

如果是表单,则像这样放入提交中: <form method='POST' action='' onsubmit='return interaction()'>在函数端,做一个return false;

type:'POST'有点不

推荐使用,请改用method:'POST'。而不是像这样使用success

$.ajax({....... your stuff .......}).done(function(data){
window.location.reload(); //whats the point of using ajax here, if you do a reload then?
})

最新更新