var app = { getWhatever: function() { $.ajax({ type: "GET", url: "http://bitbonsai.kodingen.com/cors.php", contentType: "application/json", dataType: "text", success: function(data) { $("#putResponse").text(data); } }); }, getAge: function() { $.ajax({ type: "GET", url: "http://bitbonsai.kodingen.com/cors.php", contentType: "application/json", data: { age: 37 }, dataType: "text", success: function(data) { $("#putResponse").html(function() { return this.innerHTML + '<br>' + data; }); } }); }, init: function() { this.getWhatever(); this.getAge(); } }; app.init();
<h1>Cross-Origin Resource Sharing (CORS) With jQuery</h1> <hr /> <code id="putResponse"> loading... </code>
body{ background: #fafafa; font-family: sans-serif; padding: 1em; }