【问题标题】:How to make a GET request with cljs-ajax to a source outside my server如何使用 cljs-ajax 向我的服务器外部的源发出 GET 请求
【发布时间】:2017-08-21 21:56:03
【问题描述】:

我正在尝试使用 cljs-ajax 使用 clojurescript 向服务器外部的资源发出简单的 GET 请求。我的代码 core.cljs 如下所示:

(ns btc-data-miner.core
    (:require [clojure.browser.repl :as repl]
              [ajax.core :refer [GET POST]]))

(defn handler [response]
    (.log js/console (str response)))

(defn error-handler [{:keys [status status-text]}]
    (.log js/console (str "something bad happened: " status " " status-text)))

(GET "www.okcoin.com/api/v1/ticker.do?symbol=btc_usd" {:handler handler
                                                           :error-handler error-handler})

但它总是在我的网站内搜索文件,就好像 a 正在传递 /resource 而不是完整路径。如何向外部来源提出请求?

【问题讨论】:

    标签: ajax clojure clojurescript cljs-ajax


    【解决方案1】:

    www.okcoin.com/api/v1/ticker.do?symbol=btc_usd 是一个相对 URL。因此它将相对于当前页面(大概在您的服务器上)进行解析。如果您希望它解析到不同的服务器,您需要使用绝对 URL - 例如,http://www.okcoin.com/api/v1/ticker.do?symbol=btc_usd

    【讨论】:

      猜你喜欢
      • 2022-10-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-01-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多