我对下面的代码没有任何困惑,我只是不明白这是哪种网址:/echo/json/
。
看到这个jsfiddle。
您可以看到数据已发布到该URL,/echo/json/
但是此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/
,我想知道它的工作方式。
正如@nemesv在评论中指出的那样,这是JSFiddle的功能。
所述的jsfiddle文档提供这些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();
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句