No response with jquery-mockjax

家住魔仙堡 提交于 2019-12-11 11:07:50

问题


I am trying to use jquery-mockjax library to mock ajax, but I cannot see any response. My code is as follow :

<!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>

Is there anything I am missing?


回答1:


I had this same problem and was banging my head for half an hour, and shouting "why?"

Try downgrading jQuery to 1.*




回答2:


ResponseTime increase.

responseTime: 10,


来源:https://stackoverflow.com/questions/16411978/no-response-with-jquery-mockjax

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!