【问题标题】:How can I access the Internet via a JavaScript program in Microsoft Visual Studio 2017?如何通过 Microsoft Visual Studio 2017 中的 JavaScript 程序访问 Internet?
【发布时间】:2019-04-01 21:35:56
【问题描述】:

我正在尝试在 Visual Studio 上使用 Java Script 编写一个程序,该程序需要使用 Internet 来定义一个变量,但我该怎么做呢?我的程序要求在 Google 上搜索用户输入以返回某些信息。我是 Visual Studio 的新手,所以我不确定从哪里开始。谢谢!

【问题讨论】:

    标签: javascript visual-studio google-chrome visual-studio-2017


    【解决方案1】:

    这真的取决于你想要的变量。如果你有一个 API 端点,你可以使用它们的 fetch 函数来获取数据。但是,如果您不打算在浏览器中运行该程序,则需要安装nose 和node-fetch 来执行此操作。 如果您更想根据输入在浏览器中模拟某些内容,则必须使用 puppeteer 之类的东西。

    你必须在这里更清楚你想要做什么。

    【讨论】:

      【解决方案2】:

      我建议你使用 Ajex 和 Rest Api。

      例子:

      var key = "abc"; // your api key registered with google.
      
      $.ajax({
        url: "https://www.googleapis.com/customsearch/v1?key="+key+"q="+query
      }).then(
        function(data){
          // read data from here...
        }
      )

      参考:

      Using REST to Invoke the API

      【讨论】:

        【解决方案3】:

        既然您提到了 Google 搜索,那就是 Google 的 Angular 框架。还有其他的,来自 Facebook 和 jQuery 的 React。所有这些都是 JavaScript,可以在 Visual Studio 中使用。 他们有自己的方法和学习曲线。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2018-06-10
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2017-11-05
          • 2020-05-19
          • 1970-01-01
          相关资源
          最近更新 更多