2
我試圖調用Mockjax「後」通過jQuery的$。員額法終點後mockjax服務如下
service.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>
但是在調用該方法時,resp總是未定義。 這裏有什麼可能是錯的?