1

我正在尝试在重新构建应用程序中实现此答案的破解。

从某种意义上说,我实际上收到了确认电子邮件,但它会引发错误并调度:on-failure事件。

编码:

(ns foo.events
  (:require
   [re-frame.core :as rf]
   [ajax.core :as ajax]
   [day8.re-frame.http-fx]))

(rf/reg-event-db :mc/yes
  (fn [db res] (prn res) db))

(rf/reg-event-db :mc/no
  (fn [db res] (prn res) db))

(rf/reg-event-fx :mc
  (fn [_ _]
    {:http-xhrio
     {:method :get
      :uri "https://XXX.us15.list-manage.com/subscribe/post-json?u=XXX&id=XXX&c=?"
      :format (ajax/json-request-format)
      :response-format (ajax/json-response-format)
      :params {"FNAME" "fooobar"
               "EMAIL" "some.dude@example.com"}
      :on-success [:mc/yes]
      :on-failure [:mc/no]}}))

(comment
  (rf/dispatch [:mc]) ; I execute this in my editor.
  )

错误:

Failed to load https://XXX.us15.list-
manage.com/subscribe/post-json?u=XXX&id=XXX&c=?
&FNAME=fooobar&EMAIL=some.dude@example.com: No 'Access-Control-
Allow-Origin' header is present on the requested resource. Origin 
'http://localhost:3449' is therefore not allowed access.

打印到控制台的内容:

[:mc/no {:uri "https://XXX.us15.list-manage.com/subscribe/post-json?u=XXX&id=XXX&c=?&FNAME=fooobar&EMAIL=some.dude@example.com", :last-method "GET", :last-error " [0]", :last-error-code 6, :debug-message "Http response at 400 or 500 level", :status 0, :status-text "Request failed.", :failure :failed}]

编辑:

这就是我想要的,除了取决于 jquery。这与 http-xhrio 版本有什么不同?

(defn mailchimp-signup! [data on-success on-failure]
  (-> js/$
      (.ajax #js{:type "get"
                 :data (clj->js data)
                 :url "https://XXX.us15.list-manage.com/subscribe/post-json?u=XXX&id=XXX&c=?"
                 :cache false
                 :dataType "json"
                 :contentType "application/json; charset=utf-8"
                 :error on-failure
                 :success on-success})))
4

0 回答 0