0

In my application I have a shuffle button to start and stop the mockjax response. as a first time, I am initiating the mockjax it works. later the user click on off button to stop mockjax service. ( I am showing server data )

for stop I use:

stopSimulation : function( ) {

            if( !this.retriveSimulationStatus() ) {
                console.log("i switched off!!");
                $.mockjax.clear(); //removes the simulation; 
            }

        } 

But user clicks back to start button, But mockjax not intercepting again to provide the data.

so what is the correct way to stop and start the mockjax service? any one help me?

user2024080
  • 1
  • 14
  • 56
  • 96

1 Answers1

0

Clearing the Mockjax handlers does NOT "stop" them, it erases them from Mockjax. There is no "start"/"stop" functionality. You will need to clear the handlers, then re-add the handlers when you want to start. Here's an example:

var handler = { url: '/foo', responseText: { foo: 'bar' } };

function start() {
  $.mockjax(handler);
}

function stop() {
  $.mockjax.clear();
}
Jordan Kasper
  • 13,153
  • 3
  • 36
  • 55