mockjax-sample

Simple mockjax sample

HTML

<script src="https://raw.github.com/appendto/jquery-mockjax/master/jquery.mockjax.js"></script>
<!DOCTYPE html>
<html>
    <head>
        <title>Fortune App</title>
    </head>
    <body>
        <div id="fortune"><img src="http://imgb.nxjimg.com/emp_image/offerdetail/restaurant/loading.gif" /></div>
    </body>
</html>

CSS

#fortune {
    background-color: #F0F0F0 ;
    border: 1px solid #CCCCCC ;
    padding: 15px 15px 15px 15px ;
    width: 400px ;
}

JavaScript

// The response is always the same

$.mockjax({
  url: '/restful/fortune',
  responseTime: 750,
  responseText: {
		data: {
	    status: 'success',
  	  fortune: 'Are you a turtle?'
		}
  }
});


$.getJSON('/restful/fortune', function(data) {
    if (response.status == 'success') {
        $('#fortune').html('Your fortune is: ' + response.fortune);
    } else {
        $('#fortune').html('There is a problem with the request');
    }
});