2013-05-07 131 views
1

我想用jquery-mockjax库来模拟ajax,但我看不到任何响应。 我的代码如下:jquery-mockjax没有响应

<!doctype html> 
<html lang="en"> 
<head> 
    <meta charset="UTF-8"> 
    <title>Document</title> 
    <script src="components/jquery/jquery.js"></script> 
    <script src="components/jquery-mockjax/jquery.mockjax.js"></script> 
    <script> 
     $(function(){ 
      $.mockjax({ 
       url: '/test/inline', 
       contentType: "text/json", 
       responseTime: 0, 
       responseText: { 
        say: 'Hello world!' 
       } 
      }); 

      $('#btn').click(function(){ 
       $.ajax({ 
        url: '/test/inline', 
        type: "GET", 
        dataType: 'json', 
        success: function(json) { 
         alert('You said: ' + json.say); 
        }, 
        complete: function() { 
         $.mockjaxClear(); 
         alert('completed'); 
        } 
       }); 
      } 
      ); 
     }); 
    </script> 
</head> 
<body> 
    <button id="btn">Get</button> 
</body> 
</html> 

有什么我失踪?

+0

我找到了原因。我使用的jquery版本> 2.0 – Ray 2013-05-07 06:11:11

+1

将jquery版本降级到1.9.1后,它的工作原理! – Ray 2013-05-07 06:11:43

+0

请发表您的答案作为答案,而不是评论。另外,你正在使用哪个版本的mockjax? – Flimzy 2014-06-06 02:08:13

回答

2

我有这个同样的问题,在敲打我的头半小时,并高呼“为什么?”

尝试将jQuery降级为1. *

0

ResponseTime增加。

responseTime: 10,