<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>jquery examples - 4</title>
<link rel="stylesheet" type="text/css" href="css/style2.css">
</head>
<body>
<input id="name" type="text" name="">
<input id="button" type="button" value="load" name="">
<div id="content"></div>
<script type="text/javascript" src="js/jQuery.js"></script>
<script type="text/javascript" src="js/selectors12.js"></script>
</body>
</html>Run Code Online (Sandbox Code Playgroud)
$('#button').click(function() {
var name = $('#name').val();
$.ajax({
url:'php/page.php',
data: 'name='+name, //sending the data to page.php
success: function(data) {
$('#content').html(data);
}
}).error(function() {
alert('an error occured');
}).success(function() {
/*alert*/
alert('an error occured');
}).complete(function() {
/*alert*/
});
});Run Code Online (Sandbox Code Playgroud)
在error()不工作,当我改变的网址:以page.php不正确的扩展以检查error()和显示。
但是,在控制台中,它显示一条错误消息:
未捕获的TypeError:$ …