[英]$.ajax not working and bypassing in onclick event
我的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()但无法正常工作。
如果是表单,则将其放入onsubmit中,如下所示: <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?
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.