Search code examples
jqueryresponsemockjax

I'm getting null response from mockjax


I have this:

$.ajax({
    url:        '/autocomplete',
    type:       'GET',
    dataType:   'json',
    success:    function(data) {
        alert(data);
    }
});

and trying to mock it with:

$.mockjax({
    url:            '/autocomplete',
    type:           'GET',
    responseTime:   50,
    responseText:    function() {
        this.responseText = {info: 'Merge !!!'};
    }
});

I'm getting NULL as a response from mocjax.

What am I doing wrong? How can I use the response function in mockjax


Solution

  • Instead of

    responseText
    

    it should be just

    response
    

    So, the correct version is:

    response:    function() {
        this.responseText = {info: 'Merge !!!'};
    }