这个 jsfiddle 中的 url /echo/json/ 是做什么的?
What does the url /echo/json/ in this jsfiddle do?
我对下面的代码没有混淆,我只是不明白这是什么url:/echo/json/
。
您可以看到数据已发布到此 url /echo/json/
,但此 url 可能不存在。那么请告诉我这个 url /echo/json/
是如何工作的。
$.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'
});
我唯一的问题是这个 url /echo/json/
,我想知道它是如何工作的。
正如评论中指出的那样,这是 JSFiddle 的一个特性。
The JSFiddle docs 提供这些 URL(/echo/html
、/echo/json
、/echo/jsonp
、/echo/xml
和 /echo/js
)作为简单回显给定数据的存根。您可以使用它来模拟具有可选指定延迟的响应,这对于测试不存在的 REST 操作或 AJAX 某种调用处理程序非常有用,例如。
使用原始 Javascript 中的 JSON URL 的格式如下(从他们的示例页面中提取):
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();
我对下面的代码没有混淆,我只是不明白这是什么url:/echo/json/
。
您可以看到数据已发布到此 url /echo/json/
,但此 url 可能不存在。那么请告诉我这个 url /echo/json/
是如何工作的。
$.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'
});
我唯一的问题是这个 url /echo/json/
,我想知道它是如何工作的。
正如评论中
The JSFiddle docs 提供这些 URL(/echo/html
、/echo/json
、/echo/jsonp
、/echo/xml
和 /echo/js
)作为简单回显给定数据的存根。您可以使用它来模拟具有可选指定延迟的响应,这对于测试不存在的 REST 操作或 AJAX 某种调用处理程序非常有用,例如。
使用原始 Javascript 中的 JSON URL 的格式如下(从他们的示例页面中提取):
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();