$(document).ready(function() { $('input:button').click(function() { if (isNumeric($("input:first").val()) == true) { /* Call MATLAB Production Server */ var n = Number($("input:first").val()); computeFibonacciMPS(n); } else { $('#answer').text("Input needs to be numeric!"); } }); }); /* Function to compute Fibonacci series on MATLAB Production Server */ function computeFibonacciMPS(n) { /* Create a simple AJAX request to the MATLAB Production Server */ $.ajax({ url: 'http://ec2-34-206-1-112.compute-1.amazonaws.com:31415/example/fibonacci', type: "POST", data: JSON.stringify({ "rhs": n, "nargout": 1 }), contentType: 'application/json', success: function(data) { /* Parse the response when ready */ $('#answer').text(data.lhs[0].mwdata[0]); $('#answer').effect("highlight", { color: "#FFFF00" }, 1000); //console.log(data); } }); } /* Helper function to determine if input is numeric */ function isNumeric(n) { return !isNaN(parseFloat(n)) && isFinite(n); }