Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/39.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
从nodeJS解释器使用jqueryajax_Jquery_Node.js_Same Origin Policy - Fatal编程技术网

从nodeJS解释器使用jqueryajax

从nodeJS解释器使用jqueryajax,jquery,node.js,same-origin-policy,Jquery,Node.js,Same Origin Policy,我正在localhost:8080上运行一个开发服务器,现在正在一个终端上工作。我使用以下命令安装了nodejs: $ brew install node $ brew install jquery 现在我运行节点解释器: $ node > var $ = require("jquery"); > getSomething() undefined <-- this is what I get 我定义了一个函数,将它获得的任何内容打印到控制台: function getSo

我正在
localhost:8080
上运行一个开发服务器,现在正在一个终端上工作。我使用以下命令安装了
nodejs

$ brew install node
$ brew install jquery
现在我运行
节点
解释器:

$ node
> var $ = require("jquery");
> getSomething()
undefined <-- this is what I get
我定义了一个函数,将它获得的任何内容打印到控制台:

function getSomething() {
    $.get("http://localhost:8080",
          function(response) {
              console.log(response);
    });
}
因此在口译员中:

$ node
> var $ = require("jquery");
> getSomething()
undefined <-- this is what I get
>getSomething()
未定义
  • getSomething
    不返回任何内容。因此,
    undefined
    是默认的返回值。这是正确的
  • 您认为ajax在node的核心API中的哪一部分起作用?是否有可能
    window.XMLHttpRequest
    。这可能不存在吗
  • 为什么要将jQuery与node一起使用?它是为了消除跨浏览器遵从性问题吗?那是什么?他们不存在吗?那么就不要使用jQuery
  • 您可能不理解GET请求必须是异步的,因此不能返回任何内容,它将在返回GET后记录响应
  • 如果您想练习JavaScript,那么使用jQuery对您没有帮助
  • 不过说真的,发出HTTP请求的方法很简单

    $npm安装请求

    var request = require("request");
    
    function makeRequest(callback) {
      request("http://localhost:8080", callback);
    }
    
    makeRequest(function (err, res, body) {
      console.log(body);
    });