我正在尝试通过 jQuery $.post 方法调用 Mockjax 'post' 端点,如下所示
服务.js
$.mockjax({
url: '/api/callfor/data',
type: 'post',
responseTime: 1000,
contentType: 'text/json',
dataType: 'json',
responseText: {
success: true,
data: 'Hello World'
}
});
索引.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Mock Ajax call</title>
</head>
<body>
<script src="jquery-1.10.2.min.js" type="text/javascript"></script>
<script src="jquery.mockjax.js" type="text/javascript"></script>
<script src="service.js" type="text/javascript"></script>
<script type="text/javascript">
$.post('/api/callfor/data', {}, function (resp) {
var html = (resp.success) ? 'Your data is ' + resp.data : 'No data received';
});
</script>
</body>
</html>
但是在调用该方法时,响应总是未定义。这里有什么问题?