这个jsfiddle中的url/echo/json /是做什么的?

Mou*_*Mou 5 ajax jquery jsfiddle

我对下面的代码没有任何困惑,我只是不明白这是什么类型的网址: /echo/json/.

看到这个jsfiddle.

您可以看到数据已发布到此网址,/echo/json/但此网址可能不存在.那么告诉我这个网址/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'
});
Run Code Online (Sandbox Code Playgroud)

我唯一的问题是关于这个网址/echo/json/,我想知道它是如何工作的.

Sho*_*nja 6

正如@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();
Run Code Online (Sandbox Code Playgroud)