I have no confusion about the code below, I just do not understand what kind of url this is: /echo/json/
.
See this jsfiddle.
You can see that data getting posted to this url /echo/json/
but this url probably does not exist. So tell me how this url /echo/json/
is working.
$.ajax({
type: 'POST',
url: '/echo/json/',
data: {
json: ko.toJSON(entries),
delay: .1
},
success: function(entries) {
ko.utils.arrayForEach(entries, function(entry) {
viewModel.items.push(entry);
});
viewModel.pendingRequest(false);
},
error: function() {
viewModel.pendingRequest(false);
},
dataType: 'json'
});
The only issue I have is about this url /echo/json/
, I'd like to know how it is working.
As @nemesv pointed out in the comments, this is a feature of JSFiddle.
The JSFiddle docs provide these URLs (/echo/html
, /echo/json
, /echo/jsonp
, /echo/xml
, and /echo/js
) as stubs which simply echo back the given data. You can use this to emulate a response with an optionally-specified delay, which would be useful for testing a nonexistent REST action or AJAX call handler of some sort, for example.
The format for using the JSON URL from raw Javascript is as follows (ripped from their example page):
new Request.JSON({
url: '/echo/json/',
data: {
json: JSON.encode({
text: 'some text',
array: [1, 2, 'three'],
object: {
par1: 'another text',
par2: [3, 2, 'one'],
par3: {}
}
}),
delay: 3
},
onSuccess: function(response) {
show_response(response, $('post'));
}
}).send();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With