Test /echo/json
by David Buzatto
HTML
Number: <span id="numberSpan">?</span> | Text: <span id="stringSpan">?</span>
JavaScript
setInterval(
function() {
$.ajax({
type: "POST",
url: "/echo/json/",
data: {
json: JSON.stringify({
numberValue: Math.floor(Math.random() * 10 + 1),
stringValue: ["a", "b", "c", "d"][Math.floor(Math.random() * 4)]
})
},
success: function(data) {
$("#numberSpan").html(data.numberValue);
$("#stringSpan").html(data.stringValue);
}
});
},
3000
);
setInterval(
function() {
$.post(
"/echo/json/", {
json: JSON.stringify({
numberValue: Math.floor(Math.random() * 10 + 1),
stringValue: ["a", "b", "c", "d"][Math.floor(Math.random() * 4)]
})
},
function(data) {
$("#numberSpan").html(data.numberValue);
$("#stringSpan").html(data.stringValue);
}
);
},
3000
);