【发布时间】:2014-02-07 16:48:28
【问题描述】:
只是为了提供背景。我在一个普通的 html 文件中编写了以下代码。我的系统上没有服务器或任何运行的东西。我在桌面上创建了一个文件,并在其中编写了html代码。
第一种方法
<form action="http://www.google.com" method="GET">
<input type="submit"/>
</form>
第二种方法
<form action="http://www.google.com" method="GET">
<input type="button" onclick="myMethod()"/>
</form>
<script>
function myMethod(){
$.ajax({
data:'',
type: 'GET',
url: 'http://www.google.com',
success: function(response){
$(".popupdiv").html(response);
}
});
event.preventDefault();
return false;
}
</script>
当我执行第一种方法时,单击按钮时,我会被带到google.com,但通过第二种方法,什么也没有发生。甚至我的 (chrome) 控制台也没有显示任何错误。
发生了什么,有什么区别?
【问题讨论】:
标签: html ajax forms get submit