Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/413.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript $.get data打印发件人的源代码_Javascript_Jquery_Json_Ajax - Fatal编程技术网

Javascript $.get data打印发件人的源代码

Javascript $.get data打印发件人的源代码,javascript,jquery,json,ajax,Javascript,Jquery,Json,Ajax,我正在尝试将get请求发送到服务器上的URL(IP已过滤。为了示例起见,{{computer.id}}是1)-发送者 (err输出是源代码)。 在“MyData”中,有一个JSON数据(),我读到,当我在服务器上读取它时,需要将它转换为字符串(两种方式都不起作用),而不是发送JSON请求,它只发送给我整个源代码接收器-: $(document).ready(function(){ $.get("/computers/{{computer.id}}/live", functi

我正在尝试将get请求发送到服务器上的URL(IP已过滤。为了示例起见,
{{computer.id}}
1
)-发送者

(err输出是源代码)。 在“MyData”中,有一个JSON数据(),我读到,当我在服务器上读取它时,需要将它转换为字符串(两种方式都不起作用),而不是发送JSON请求,它只发送给我整个源代码接收器-:

   $(document).ready(function(){
        $.get("/computers/{{computer.id}}/live", function(data){
          console.log(data) // prints the source code of the sender
          console.log(data['running processes']) // prints undefined
          var jso = JSON.parse(json); // throws an error
          console.log(jso)
        })
        .done(function() {
    console.log( "second success" );
  })
        .fail(function(jqXHR, textStatus, error) {
    console.log( "Post error: " + error);
  })
  .always(function() {
    console.log( "complete" );
  });
});

所以“
console.log(data)
”的输出基本上是“
/computers/{{computer.id}}/live
”的源代码。我需要做什么呢?数据将是JSON数据,而不是整个文件。

在做了一些研究之后,我发现答案是因为JSON数据,我没有很好地发送它,我应该在后端对其进行措辞,并将其作为文本类型发送

或者将其解析为JSON,或者使用
$.getJSON()
@Twisty问题是。getJSON不起作用,因为出于某种原因它不是JSON,当我尝试不使用stringify时,它会做同样的事情,我会
var info=JSON.parse(data)
并查看它是否是该点上的对象。API是否返回正确的
内容类型
标题,
应用程序/json
?@Twisty在此之前已经解析过了
   $(document).ready(function(){
        $.get("/computers/{{computer.id}}/live", function(data){
          console.log(data) // prints the source code of the sender
          console.log(data['running processes']) // prints undefined
          var jso = JSON.parse(json); // throws an error
          console.log(jso)
        })
        .done(function() {
    console.log( "second success" );
  })
        .fail(function(jqXHR, textStatus, error) {
    console.log( "Post error: " + error);
  })
  .always(function() {
    console.log( "complete" );
  });
});